![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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 |
| replacing multiple lines with single line | siba.s.nayak | Shell Programming and Scripting | 3 | 05-27-2008 11:43 PM |
| Multi-line output to single line | LinuxRacr | Shell Programming and Scripting | 7 | 02-26-2008 06:05 AM |
| Concatenating multiple lines to one line if match pattern | phixsius | Shell Programming and Scripting | 13 | 01-24-2008 07:02 PM |
| Reading Multiple Variables From a Single Line in Shell | Drek | Shell Programming and Scripting | 14 | 12-21-2006 07:20 AM |
| Splitting a single line into multiple lines | thanuman | Shell Programming and Scripting | 4 | 02-23-2005 12:56 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
make multiple line containing a pattern into single line
I have the following data file.
Code:
zz=aa azxc-1234 aa=aa zz=bb azxc-1234 bb=bb zz=cc azxc-1234 cc=cc zz=dd azxc-2345 dd=dd zz=ee azxc-2345 ee=ee zz=ff azxc-3456 ff=ff zz=gg azxc-4567 gg=gg zz=hh azxc-4567 hh=hh zz=ii azxc-4567 ii=ii So the output will be: Code:
zz=aa azxc-1234 aa=aa zz=bb azxc-1234 bb=bb zz=cc azxc-1234 cc=cc zz=dd azxc-2345 dd=dd zz=ee azxc-2345 ee=ee zz=ff azxc-3456 ff=ff zz=gg azxc-4567 gg=gg zz=hh azxc-4567 hh=hh zz=ii azxc-4567 ii=ii Last edited by Yogesh Sawant; 05-22-2008 at 10:19 AM. Reason: added code tags |
| Forum Sponsor | ||
|
|
|
||||
|
If the input is ordered by the second field:
Code:
awk 'END{print RS}$0=_[$2]++||NR==1?$0:RS$0' ORS= input
Code:
awk 'END{for(r in _)print _[r]}{_[$2]=_[$2]?_[$2] FS $0:$0}' input
Last edited by radoulov; 05-22-2008 at 01:23 PM. |
|
|||
|
help!
Can you guys please help me do the following.
I have a file with a server name and a list of mac addresses (variable length) on separate lines, need to put them all in one line separated by space: Have this: servername 00:03:6e:4e:4f:5c 00:09:7b:4e:4c:6d 00:04:55:5a:8d:ec .... want this: servername 00:03:6e:4e:4f:5c 00:09:7b:4e:4c:6d 00:04:55:5a:8d:ec .... Can someone please help, thanks so much.... Sara |
|
||||
|
Use nawk or /usr/xpg4/bin/awk on Solaris:
Code:
awk 'END { print _ }
!/:/ && _ { print _; _ = "" }
{ _ = _ ? _ FS $0 : $0 }
' filename
Code:
perl -nle'BEGIN { $, = " " }
print @x and undef @x if not /:/ and @x;
push @x, $_;
END { print @x }
' filename
Last edited by radoulov; 4 Weeks Ago at 12:37 AM. Reason: refactored |
|
|||
|
Thanks so much for your response however, I am getting error when running the command, any chance you can take a look? Thanks again.
>awk 'END { print _ } > !/:/ && x++ { print _; _ = "" } > { _ = _ ? _ FS $0 : $0 } > ' file.mac awk: syntax error near line 2 awk: bailing out near line 2 |
|||
| Google UNIX.COM |