- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: join lines in a file
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
тАО11-11-2008 02:52 PM
тАО11-11-2008 02:52 PM
I have a problem similar to the one in this thread.
http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1202845
But, in my case the file is of this format.
---
line1.1
line1.2
line1.3
line2.1
line2.2
line2.3
line2.4
line3.1
line3.2
---
I want the following output
---
line1.1line1.2line1.3
line2.1line2.2line2.3line2.4
line3.1line3.2
---
So, basically I've to join the lines until a empty line is encountered. Then , i have to skip it and start joining other lines. I am unable to do it with my limited knowledge of awk.
Any help is appreciated.
Thanks
Saini
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 03:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 03:35 PM
тАО11-11-2008 03:35 PM
Re: join lines in a file
One way:
# perl -le '$/="";while (<>) {chomp;s/\n/ /g;print}' file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 08:05 PM
тАО11-11-2008 08:05 PM
Re: join lines in a file
Dennis: I am sorry to say from your awk the output is comming like, see the below
line1.1 line1.2 line1.3
line1.1 line1.2 line1.3 line2.1 line2.2 line2.3 line2.4
line1.1 line1.2 line1.3 line2.1 line2.2 line2.3 line2.4 line3.1 line3.2 line1.1
line1.1 line1.2 line1.3 line2.1 line2.2 line2.3 line2.4 line3.1 line3.2 line1.1 line1.2 line1.3
line1.1 line1.2 line1.3 line2.1 line2.2 line2.3 line2.4 line3.1 line3.2 line1.1 line1.2 line1.3 line2.1
Saini required this output
line1.1line1.2line1.3
line2.1line2.2line2.3line2.4
line3.1line3.2
Saini please use this awk script for the same output you required
awk '
{
if (substr($0,1,1)=="l") printf "%s ",$1
else
printf "\n\n"
}'
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 08:33 PM
тАО11-11-2008 08:33 PM
Re: join lines in a file
Oops, forgot to reset "save":
awk '
{
if ($0 == "") {
print save
save = ""
next
}
save = save $0 # concatenate
}
END { print save }' file
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2008 05:07 AM
тАО11-12-2008 05:07 AM
Re: join lines in a file
OK, I see from your last post that your do not want a space between the tokens on each line.
I also see from your last post that you *do* want the blank line preserved between groups.
Lastly, it appears that you don't want a trailing blank line, so I'll suppress that.
Those are trivial adjustments. Hence:
# perl -le '$/="";while (<>) {s/\n//g;printf "%s\n",(eof) ? $_ : "$_\n"}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2008 07:30 AM
тАО11-12-2008 07:30 AM
Re: join lines in a file
Saini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2008 07:31 AM
тАО11-12-2008 07:31 AM