- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: sed new line not working
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
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
тАО11-04-2008 04:19 AM
тАО11-04-2008 04:19 AM
sed new line not working
2lines line1 line2 sed 's/#test/&\n'line1"\n"line2'/' file
Not working.
My output:
#testnline1nline2
1
2
Sed version is 3.02
What is wrong ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-04-2008 05:04 AM
тАО11-04-2008 05:04 AM
Re: sed new line not working
sounds wierd that the \n doesn't work... it should work with any version of sed imo.
But, I'm not sure this will work since I don't have anything to test it on :P
$~> sed "/#test/ a\line1\;a\line2\" file
Otherwise this should also work:
$~> sed -e "/#test/ a\line1\" -e "/line1/ a\line2\" file
a\ is append after matched line.
Hope this helps you :)
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-04-2008 10:49 PM
тАО11-04-2008 10:49 PM
Re: sed new line not working
On sed 4.02 works fine.
sed 's/#test/&\n'line1"\n"line2'/' file
On sed 3.02 \a not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-06-2008 12:30 AM
тАО11-06-2008 12:30 AM
Re: sed new line not working
The part "/#test/" will search for any occurance of #test. "a\Line1" will append after the matched occurance the trailing characters that is listed after "\".
But as he said, didn't work... I tried it last night and found that \n is probably the only reasonable way unless you do 2 sed's.
$~> sed -i "/#test/ a\Line1" file.txt
$~> sed -i "/Line1/ a\Line2" file.txt
but since "-i" parameter changes the original file maybe it's better to "-e" and redirect the output to a new file like this
$~> sed -e "/#test/ a\Line1" file.txt > newfile.txt
$~> sed -i "/Line1/ a\Line2" newfile.txt
But if your version works now with \n, I would say it's simpler too use my method described above.
$~> sed -e "/#test/ a\Line1\nLine2" file.txt
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-06-2008 01:20 AM
тАО11-06-2008 01:20 AM
Re: sed new line not working
sed: invalid option -- i
$~> sed -e "/#test/ a\Line1" file.txt > newfile.txt
sed: -e expression #1, char 11: Extra characters after command
My version works with \n only on 4.02 version, I need to work on another box with 3.02 sed version
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-06-2008 08:58 AM
тАО11-06-2008 08:58 AM
Re: sed new line not working
sed 's/#test/&\^Jline1\^Jline2/' testfile
Where it says ^J, do [CTRL+V][CTRL+J].
David