- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- joining consecutive 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
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
05-30-2002 11:33 PM
05-30-2002 11:33 PM
joining consecutive lines
I have file which looks like :
xxxxxxxxxx
xxx pattern xxx
yyy
xxx pattern xxx
yyy
xxxxxxxx
I would like to join consecutive lines so the output looks like :
xxxxxxxxxx
xxx pattern xxxyyy
xxx pattern xxxyyy
xxxxxxxx
How can this be realised with a simple sed or awk statement ?
Thanks in advance.
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2002 11:40 PM
05-30-2002 11:40 PM
Re: joining consecutive lines
sed '/pattern/N;s/\n/ /' filename
This will join only the lines with the pattern.
Thanks anyway.
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2002 11:42 PM
05-30-2002 11:42 PM
Re: joining consecutive lines
you forgot to assign points to yourself for the quick solution of your problem....
:-)
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2002 11:49 PM
05-30-2002 11:49 PM
Re: joining consecutive lines
Unfortunately you can not assign points for your own solutions. If that would have succeeded, then that would be my first points to be honest.
Regards,
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2002 12:53 AM
05-31-2002 12:53 AM
Re: joining consecutive lines
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x3b617bb04b5cd611abdb0090277a778c,00.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2002 01:33 AM
05-31-2002 01:33 AM
Re: joining consecutive lines
Seems that the problem is a bit more complicated. It is sometimes necessary to join 3 or more lines.
Suppose the file looks like :
xxxxx
xx patternA xx
patternB
xxxxx
xx patternA xx
xxxxx
patternB
xxxxx
The result file should like like :
xxxxx
xx patternA xxpatternB
xxxxx
xx patternA xxxxxxxpatternB
xxxxx
Any suggestions,
Thanks in advance
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2002 02:11 AM
05-31-2002 02:11 AM
Re: joining consecutive lines
I found the solution for the real problem, not on my last question :
cat file.org | sed -e '/startpattern/,/endpattern$/ d' > file.new
This will delete every block (multiple consecutive lines ) in the file starting with a line containing the startpattern and ending with a line ending with the endpattern.
Thanks anyway.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2002 02:18 AM
05-31-2002 02:18 AM
Re: joining consecutive lines
Below works on the assumption that "xx patternA" can itself be a static pattern. Apart from that, no problems getting everything from patternA to patternB to be on a the same line:
bash-2.05a# cat tstfile
xxxxx
xx patternA xx
patternB
xxxxx
xx patternA xx
xxxxx
patternB
xxxxx
bash-2.05a# echo `cat tstfile` | sed "s/ xx patternA/;xx patternA/g" | sed "s/patternB /patternB;/g" | tr [";"] ["\n"]
xxxxx
xx patternA xx patternB
xxxxx
xx patternA xx xxxxx patternB
xxxxx
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2002 02:58 AM
05-31-2002 02:58 AM
Re: joining consecutive lines
Suppose the file looks like :
xxxxx
xx patternA xx
patternB
xxxxx
xx patternA xx
xxxxx
patternB
xxxxx
The result file should like like :
xxxxx
xx patternA xxpatternB
xxxxx
xx patternA xxxxxxxpatternB
xxxxx
# perl -pe 'BEGIN{$/="xxxxx\n"}chomp;s/\n/ /g;$_.=$/' xx.txt
xxxxx
xx patternA xx patternB xxxxx
xx patternA xx xxxxx
patternB xxxxx