1753973 Members
8396 Online
108811 Solutions
New Discussion юеВ

Re: Organize data

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor

Re: Organize data

You can try the following. If you don't care about stable sorts, you don't need that nl(1):
# number lines if stable sort needed
nl -ba -nrz file | sort -k2,2 -k1n,1n | awk '
BEGIN { LAST="" }
{
if ($2 != LAST) { # list header
if (LAST != "") print "===="
print $2
LAST = $2
}
# print rest of line
for (i = 3; i < NF; ++i) printf $i " "
print $NF
}
END { print "====" } '
Arturo Galbiati
Esteemed Contributor

Re: Organize data

Hi Andre,
this run fine on my HPUX11i:

#!/usr/bin/ksh
sort your_file -o temp_file
for key in $(cut -d " " -f1 temp_file|uniq)
do
echo $key
grep "^$key " temp_file| cut -c 3-
echo "="
done
rm temp_file

HTH,
Art

Re: Organize data

Hi again guys,

I wanna thank you for the replies, now I have a lot of ideas to my script, all these answers works very very well.

Finally, thanks to Dennis and Arturo for the simple scripts.

You are great... This foruns help much more than a lot of books.

Andr├Г┬й
Andre Augusto

Re: Organize data

Close
Andre Augusto