- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Can sed scripts insert new lines?
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
тАО06-09-2003 10:49 PM
тАО06-09-2003 10:49 PM
Can sed scripts insert new lines?
I'm trying to replace a combination of two lines with some text using sed. I have a problem when the first line is duplicated as I need sed to insert a newline. I have tried using \n and \\n to insert the newline in place of my obviously wrong NEWLINE in my attempt below, but it still does not work.
Can anyone help me?
Thanks.
Paul.
#!/bin/sed -f
/FirstLine/ {
# Read in the next line of input.
N
# Remove Duplicate.
/FirstLine\n\(.*FirstLine\)/ {
#####################################
# The Following Line does not work. #
#####################################
s/FirstLine\n\(.*FirstLine\)/NEWLINE\1/
# Read in the next line of input.
N
}
# Replace the match.
s/FirstLine\n.*SecondLine/PERFECT MATCH/
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2003 10:55 PM
тАО06-09-2003 10:55 PM
Re: Can sed scripts insert new lines?
here is a little suggestion:
Add new line at the middle using some pattern
# sed 's/111/111Z/g' test | tr "111Z" "111\012]" add newline after "111"
I don't know if it is applicable but it show how to put the newline, using "tr".
HTH,
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 12:54 AM
тАО06-10-2003 12:54 AM
Re: Can sed scripts insert new lines?
The tr command does not compare strings, but corresponding position letters in a string.
In the example every "Z" will be replaced with "\012", (every 1 will be replaced with 1)
Not sure it is the desired result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2003 02:55 AM
тАО06-11-2003 02:55 AM
Re: Can sed scripts insert new lines?
Don't know if you have tried this also...
Give back slash for \n at s/FirstLine\n\(.*FirstLine\)/NEWLINE\1/ ???
Try
s/FirstLine\\n\(.*FirstLine\)/NEWLINE\1/ .
Regards
VJ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2003 09:37 AM
тАО06-11-2003 09:37 AM
Re: Can sed scripts insert new lines?
<>
gives the attached script to print only one version of any duplicate line
in a file.
BTW, sed.sourceforge.net is a good source for sed scripts
Cheers,
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2003 05:16 PM
тАО06-11-2003 05:16 PM
Re: Can sed scripts insert new lines?
Then i read the link that Fix gave me and I got the nice way i was hoping to do it (so I could use sed for everything).
To put a new line in the replacement string you backslash the line and continue on the following so my line would be:
s/FirstLine\n\(.*FirstLine\)/\1/
Paul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2003 05:28 PM
тАО06-11-2003 05:28 PM
Re: Can sed scripts insert new lines?
s/FirstLine\n\(.*FirstLine\)/\CR
\1/
Paul.