The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get next 2 lines after a "pattern line" fongthai UNIX for Dummies Questions & Answers 2 05-09-2008 01:20 AM
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 12:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 01:15 AM
Help~~join and "multijoin" hyo77 Shell Programming and Scripting 1 11-18-2003 10:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-19-2005
Registered User
 

Join Date: Jun 2005
Posts: 4
join two lines when the second line contains "US DOLLAR"

I want to join two lines together when the second line contains "US DOLLAR".
How to do that with sed?

Original file:
# cat testdata
Sep. 24, 2005 Sep. 26, 2005 PHARMA PLUS DRUGMART 1149 $5.85
Sep. 25, 2005 Sep. 27, 2005 99 RESTAURANT #015
$11.00 US DOLLAR @ 1.203636 $13.24
Sep. 25, 2005 Sep. 26, 2005 ROYAL TREASURE RESTAURANT $91.66


$ od -c testdata
0000000 S e p . 2 4 , 2 0 0 5 S
0000020 e p . 2 6 , 2 0 0 5 P H
0000040 A R M A P L U S D R U G M A
0000060 R T 1 1 4 9 $ 5 . 8 5
0000100 \n S e p . 2 5 , 2 0 0 5
0000120 S e p . 2 7 , 2 0 0 5
0000140 9 9 R E S T A U R A N T # 0
0000160 1 5 \n $ 1 1 . 0 0 U S D O
0000200 L L A R @ 1 . 2 0 3 6 3 6
0000220 $ 1 3 . 2 4 \n S e p .
0000240 2 5 , 2 0 0 5 S e p . 2
0000260 6 , 2 0 0 5 R O Y A L T
0000300 R E A S U R E R E S T A U R A
0000320 N T $ 9 1 . 6 6 \n \n
0000337

Result:
Sep. 24, 2005 Sep. 26, 2005 PHARMA PLUS DRUGMART 1149 $5.85
Sep. 25, 2005 Sep. 27, 2005 99 RESTAURANT #015 $11.00 US DOLLAR @ 1.203636 $13.24
Sep. 25, 2005 Sep. 26, 2005 ROYAL TREASURE RESTAURANT $91.66
Reply With Quote
Forum Sponsor
  #2  
Old 10-20-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Using awk...
Code:
awk '{printf (NR==1||/US DOLLAR/?"":ORS) $0}END{printf ORS}' testdata
Reply With Quote
  #3  
Old 10-21-2005
Registered User
 

Join Date: Jun 2005
Posts: 4
It works.
Thank you.

Quote:
Originally Posted by Ygor
Using awk...
Code:
awk '{printf (NR==1||/US DOLLAR/?"":ORS) $0}END{printf ORS}' testdata
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0