sorting output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sorting output
# 1  
Old 01-08-2007
sorting output

hi,

I get an output like

uid=user1
gecos=user

uid=user2
gecos=admin

gecos=sol admin
uid=user3

uid=user4
gecos=sol, admin

and need it modified to:

uid=user1
gecos=user

uid=user2
gecos=admin

uid=user3
gecos=sol admin

uid=user4
gecos=sol, admin

the file has about 180 lines and ~4 paragraphs are not in correct order

thanks alot in advance Smilie

funksen
# 2  
Old 01-08-2007
Code:
$ cat datafile
uid=user1
gecos=user

uid=user2
gecos=admin

gecos=sol admin
uid=user3

uid=user4
gecos=sol, admin

$ cat scr
#! /usr/bin/ksh

awk  '  /^uid/ { u=$0 }
        /^gecos/ { g=$0 }
        /^$/  { print ; print u ; print g }'
$ ./scr < datafile

uid=user1
gecos=user

uid=user2
gecos=admin

uid=user3
gecos=sol admin

uid=user4
gecos=sol, admin
$

# 3  
Old 01-09-2007
Code:
sed "/^gecos/{N;s/\(.*\)\n\(uid=.*\)/\2\\
\1/;}" file

# 4  
Old 01-09-2007
great job, both are working perfectly

many thanks

cheers funksen
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting out unique values from output of for loop.

Hi , i have a belwo script which is used to get sectors per track value extarcted from Solaris machine: for DISK in /dev/dsk/c*t*d*s*; do value=`prtvtoc "$DISK" | sed -n -e '/Dimensions/,/Flags/{/Dimensions/d; /Flags/d; p; }' | sed -n -e '/sectors\/track/p'`; if ; then echo... (4 Replies)
Discussion started by: omkar.jadhav
4 Replies

2. Shell Programming and Scripting

Sorting output of AWK array

I need help to sort the output of an awk array Example datadata="1 blue 2 green 3 blue 4 yellow 5 blue 6 red 7 yellow 8 red 9 yellow 10 yellow 11 green 12 orange 13 black" My awk line to get output in one lineecho "$data" | awk ' {arr++; next} END { for (i in arr) { if(arr>1 )... (2 Replies)
Discussion started by: Jotne
2 Replies

3. Shell Programming and Scripting

sorting output of echo

can someone please tell me who to sort the numerical output of echo? UIO="8180 0 0 0 0 0 0 0 0 0 0 48240 48240 48240 48240 48240 48240 0 0 0 0 0 0 0 48300 0 0 0 48300" echo $UIO | sort -n This doesn't workk. it does not sort the numbers from smallest to highest. any ideas? (2 Replies)
Discussion started by: SkySmart
2 Replies

4. Shell Programming and Scripting

Sorting awk array output?

Hi all, I have a script which produces a nice table but I want to sort it on column 3. This is the output line in the script: # Output { FS = ":"; format = "%11s %6s %-16s\n"; prinft "\n" printf ( format, "Size","Count","Who" ) } for (i in... (21 Replies)
Discussion started by: Cowardly
21 Replies

5. HP-UX

Sorting top command output in HP_UX 11.11

Hello all, I've been woking on Solaris and Linux (Red Hat) so far but now I've inherited an HP-UX system and having minor issues with syntax...Appreciate if you could help me out here.. 1) I'm trying to sort the output of the top command in HP-UX 11.11 by pressing O (capital O) after typing... (2 Replies)
Discussion started by: luft
2 Replies

6. UNIX for Dummies Questions & Answers

Help Needed with Sorting Output

Hi all, I'm using Solaris 10, and need help in sorting the below output from the syslog file in descending rather than ascending order. I would like both the hostname and message columns to be sorted, but right now only the message is sorted and the count column, whose order I would like... (2 Replies)
Discussion started by: wthomas
2 Replies

7. UNIX for Dummies Questions & Answers

sorting cksum output.

Hi guys, I have a service directory with a lot of files in. I have to cksum the whole directory and compare it to a release note document. However the problem I have is the files are listed in different lines when running cksum as they are in the release doc. Therefore cksum shows... (1 Reply)
Discussion started by: Stin
1 Replies

8. Shell Programming and Scripting

Sorting/Filed Defining/Output problem

need a little help with a few tid bits. I wrote a script that checks the resoluion of image files and writes them out to a file then sorts the resolutions by largets Width. Then take the sorted files information and toss all the 835 widths into a seperate file. Ignore the redundancies its a... (1 Reply)
Discussion started by: TiredOrangeCat
1 Replies

9. Shell Programming and Scripting

Sorting problem "sort -k 16,29 sample.txt > output.txt"

Hi all, Iam trying to sort the contents of the file based on the position of the file. Example: $cat sample.txt 0101020060731 ## Header record 1c1 Berger Awc ANP20070201301 4000.50 1c2 Bose W G ANP20070201609 6000.70 1c2 Andy CK ANP20070201230 28000.00... (3 Replies)
Discussion started by: ganapati
3 Replies

10. UNIX for Dummies Questions & Answers

Sorting "ls" output on more than 1 column

I would sort the "ls" output : on the 1st column then on the nineth : ls -al |sort -k1,1 -k9,9r this doesn't work ? Anybody have an idea ? regards Christian (1 Reply)
Discussion started by: Nicol
1 Replies
Login or Register to Ask a Question