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
Discussions
Discussions
Forums
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
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
тАО08-09-2009 04:06 AM - last edited on тАО01-20-2014 02:04 AM by Lisa198503
тАО08-09-2009 04:06 AM - last edited on тАО01-20-2014 02:04 AM by Lisa198503
Hi i have handfull doubts in scripting.Now m stuck up with sed.
I have heard the sed is non-interactive and used to replace words in scripts where vi is not practical.
sed 's/abc/ABC/g' test.sh
I want to know this will modify the same script and save it or create new script with new modifications or we need to direct the output new file ?
and plz also tell me other use of sed.Bcoz man page is not helpful.
regards
himacs
P.S. This thread has been moved from HP-UX>System Administration to HP-UX > languages. -HP Forum Moderator
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2009 04:49 AM
тАО08-09-2009 04:49 AM
Re: sed
Your fingers are apparently _not_ broken.
What happens when you run this command?
> and plz also tell me other use of sed.Bcoz
> man page is not helpful.
Why, because you can't read (or write)
English, or because you're too lazy to read
the stuff, or what? Perhaps a Forum search
for keywords like
sed
would find an example or two. Buy a book.
Look around on this new Inter-Web thing.
"I'm helpless. Please do my job for me."
Give me a break.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2009 05:36 AM
тАО08-09-2009 05:36 AM
Solution> I have heard the sed is non-interactive and used to replace words in scripts where vi is not practical.
That's true. The 'sed' utility is designed to be used to edit a stream of data; hence the name 'sed' from "Stream EDitor". The actions are intended to occur non-interactively.
> I want to know this will modify the same script and save it or create new script with new modifications or we need to direct the output new file ?
No and yes.
The GNU version of 'sed' which would be found in Linux distributions offers an in-place edit using the '-i' or '--in-place' option. Versions of 'sed' that are provided by HP-UX and AIX, for example, lack this feature. Perhaps that is why you have found the manpages "not helpful" --- you may have seen examples using the GNU extensions.
Thus, for tranditional 'sed' implementations you have to redirect the output to a new file and subsequently rename ('mv') the new file to the old file. Do _not_ try to use the same output file name as the input file too. This will not work.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2009 05:50 AM
тАО08-09-2009 05:50 AM
Re: sed
Thanx for ur reply.. cleared my doubt.
I have always found ur replies are more informative and very simple to understand.
Thanx a lot
regards
himacs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2009 11:15 AM
тАО08-09-2009 11:15 AM
Re: sed
If these are scripts, you'll also have to make them executable with chmod(1).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2009 02:46 PM
тАО08-09-2009 02:46 PM
Re: sed
>Dennis: If these are scripts, you'll also have to make them executable with chmod(1).
Of course that's true if you use the traditional methods of shelll redirection to a new output file since the shell uses a creation mode mask of 0666 to which the process's umask is then applied. THus following the 'mv' ('rename') a 'chmod' could have to be used to add executable permissions.
_IF_, however, instead of 'sed' one uses Perl's inplace edit feature [ and I'm not sure if this works the same in GNU sed ] then this is not an issue. Perl will leave the permissions of the modified file unchanged:
# perl -pi -e 's/abc/ABC/g' myfile
...edits "myfile" in-place.
# perl -pi.old -e s/abc/ABC/g' myfile
...edits "myfile" in-place but makes a backup copy of the original file suffixed with ".old".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-09-2009 03:58 PM
тАО08-09-2009 03:58 PM
Re: sed
...and as one might expect, the permissions of the file to be edited are also preserved when using a GNU 'sed' in-place edit:
# sed -ie 's/abc/ABC/g' test.sh
# sed --version
GNU sed version 4.1.5
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2009 05:08 AM
тАО08-10-2009 05:08 AM
Re: sed
sed 's/abc/ABC/g' test.sh > some_temp_file
cat some_temp_file > test.sh
if the file is something other than text, this method has shortcomings but for text files, such as shell scripts, it works mighty fine.
Hope this helps
UNIX because I majored in cryptology...