![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Using awk...
Code:
awk '{printf (NR==1||/US DOLLAR/?"":ORS) $0}END{printf ORS}' testdata
|
|
#3
|
|||
|
|||
|
It works.
Thank you. Quote:
|
|||
| Google The UNIX and Linux Forums |