Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello! i hope somebody can help me.
I would like to have help with an shell script(sh) assignment.
I have a file and it contains something like the following text:02gozal:godam:godhar:TGFGK:halllo
23david:david:edsson:FDSFF:halllo
32farad:fazdg:forum:HGHJ:halllo
and so on...
Now I want a script code to take this file and print out the following text.. (skriptexample.sh textx.txt)23david david, edsson
32farad fazdg, forum
02gozal godam, godhar
and on...The last word should be in a alphabetical order.
I have started writing down the code:
sort -k3 -t: $1 | cut -f1,2,3 -d':' |
after this it get's a little bit confusing
while
IFS=:
read a
read b
read c
do
echo "$a $b $c"
doneSo please help me, a really want to know but I don't know what to do :(
I hope you can email me and help me /Anja

Hi:
Why not use awk to parse the file and sort on the 3rd field:
awk ' BEGIN { FS=":" }
{
printf("%s %s, %s\n", $1, $2, $3)
} ' file.txt|sort -k 3,3Regards,
Nails

Hi,
a sh solution could be
IFS=:
sort -k3 -t: bla.txt | while read a b c rest
do
echo $a $b $c
done
IFS='
'
No RISK no funFrank

![]() |
E-mail script
|
Recursive mget?
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |