- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need help on scripting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 05:57 PM
01-28-2004 05:57 PM
Please help on my scripting problem below. On my script, I want to replace all lines that contain a specific word to particular entry. For example, file1 contains :
flower rose red
fruit apple sweet
fruit orange sweet
fruit water melon not sweet
Want to replace all lines that contain fruit with word ' FRUIT NICE', so the target file will be as below:
flower rose red
FRUIT NICE
FRUIT NICE
FRUIT NICE
Thanks in advance.
Regards,
Negara
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:02 PM
01-28-2004 06:02 PM
Re: Need help on scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:06 PM
01-28-2004 06:06 PM
Re: Need help on scripting
mv filename.new filename
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:08 PM
01-28-2004 06:08 PM
Re: Need help on scripting
# sed -e 's/fruit/FRUIT NICE/g' file1
flower rose red
FRUIT NICE apple sweet
FRUIT NICE orange sweet
FRUIT NICE water melon not sweet
It is now what I want. I want this output :
flower rose red
FRUIT NICE
FRUIT NICE
FRUIT NICE
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:11 PM
01-28-2004 06:11 PM
Re: Need help on scripting
But it gave me the output below.
# sed /fruit/s/fruit/FRUIT\ NICE/g file1
flower rose red
FRUIT NICE apple sweet
FRUIT NICE orange sweet
FRUIT NICE water melon not sweet
Please help. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:13 PM
01-28-2004 06:13 PM
Re: Need help on scripting
Thanks. It looks fine. But it is possible use a shell sctipt instead of perl?
Thanks.
# perl -pe's/.*\bfruit\b.*/FRUIT NICE/i' file1
flower rose red
FRUIT NICE
FRUIT NICE
FRUIT NICE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:22 PM
01-28-2004 06:22 PM
Re: Need help on scripting
procura's answer works. sed and awk are not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:26 PM
01-28-2004 06:26 PM
Re: Need help on scripting
Thanks for your great help. It looks fine now.
Thanks and Best Regards,
Dewa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 06:27 PM
01-28-2004 06:27 PM
Re: Need help on scripting
#sed -e '/^fruit/s/^.*$/FRUIT NICE/g'
OR
#sed -e '/fruit/s/^.*$/FRUIT NICE/g'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 07:04 PM
01-28-2004 07:04 PM
Re: Need help on scripting
this works also:
awk '/fruit/{print "FRUIT NICE";next}{print $0}' file
Michael