- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- join lines in a file using getline
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
тАО02-12-2008 06:33 AM
тАО02-12-2008 06:33 AM
my data
some more data
my data
some more data
I want the output like
my data some more data
my data some more data
I have been looking at using the getline function to do this but I cannot quite get the systax
anyone know the best solution using awk?
thanks
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 06:38 AM
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 06:58 AM
тАО02-12-2008 06:58 AM
Re: join lines in a file using getline
s:-(
# cat chris1
this is the start
and this is the end
this is the start
and this is the end
this is the start
and this is the end
#sed '$!N;s/\n/ /' chris1
this is the start and this is the end
this is the start
and this is the end
this is the start and this is the end
or my awk effort:
# awk '{printf $0;getline;print " "$0}' chris1
this is the start and this is the end
this is the start
and this is the end
this is the start and this is the end
I wil keep trying ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 07:03 AM
тАО02-12-2008 07:03 AM
Re: join lines in a file using getline
# awk '{if (NR%2==1) {getline X};print $0,X}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 07:07 AM
тАО02-12-2008 07:07 AM
Re: join lines in a file using getline
sed '/^$/d;$!N;s/\n/ /' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 07:54 AM
тАО02-12-2008 07:54 AM
Re: join lines in a file using getline
still the same output from your command:
[root@brli013a tmp]# awk '{if (NR%2==1) {getline X};print $0,X}' chris1
this is the start and this is the end
this is the start
and this is the end
this is the start and this is the end
and this is the end
but the sed example is good ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 08:06 AM
тАО02-12-2008 08:06 AM
Re: join lines in a file using getline
Oh, so the blank lines were really there...
# awk '/^[[:space:]]*$/ {next};{if (i==0) {getline X;i=1};i=0;print $0,X}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 08:25 AM
тАО02-12-2008 08:25 AM
Re: join lines in a file using getline
and james you have given me a solution 2 for the price of 1, I amended the original file so no lines and it works ( of course )
[root@brli013a tmp]# awk '{if (NR%2==1) {getline X};print $0,X}' chris1
this is the start and this is the end
this is the start and this is the end
this is the start and this is the end
and the second solution also works well.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-12-2008 12:36 PM
тАО02-12-2008 12:36 PM
Re: join lines in a file using getline
The last suggestion of mine had extraneous (useless) code embedded, It should simply be:
# awk '/^[[:space:]]*$/ {next};{getline X;print $0,X}' file
NO POINTS FOR THE CORRECTION.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-11-2008 02:51 PM
тАО11-11-2008 02:51 PM
Re: join lines in a file using getline
I have a problem similar to the one above. 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