- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- append current line to previous line if current li...
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
тАО03-30-2004 01:06 AM
тАО03-30-2004 01:06 AM
I have a scripting question.
My source file contains lines like :
data...xb
data...95
Query:...ab
data...ab
data...a5
data...7c
data...d5
Query:...cd
data...e5
The desired output should look like :
data...95 Query:...ab
data...d5 Query:...cd
In other words, I need all lines followed by a ' Query;' line, appended with its following ' Query:' line.
Can this be done in a one-liner ?
Thanks in advance for your help.
Franky
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 01:15 AM
тАО03-30-2004 01:15 AM
Re: append current line to previous line if current line matches pattern
nawk 'BEGIN { CURRENT="" } { OLD=CURRENT ; CURRENT=$0 } { if ( match(CURRENT,"Query") ) { printf("%s %s\n",OLD, CURRENT) } }' you_file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 01:19 AM
тАО03-30-2004 01:19 AM
Re: append current line to previous line if current line matches pattern
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 01:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 01:36 AM
тАО03-30-2004 01:36 AM
Re: append current line to previous line if current line matches pattern
Thanks ... thanks ...
This is what I need.
Regards,
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 01:41 AM
тАО03-30-2004 01:41 AM
Re: append current line to previous line if current line matches pattern
awk 'BEGIN { CURRENT="" } { OLD=CURRENT ; CURRENT=$0 } { if ( substr(CURRENT,1,5)=="Query" ) { printf("%s %s\n",OLD, CURRENT) } }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 01:53 AM
тАО03-30-2004 01:53 AM
Re: append current line to previous line if current line matches pattern
This one works too for me.
Thanks.
Franky
"over and out"