Computing.Net > Forums > Unix > I need help with my skript.

I need help with my skript.

Reply to Message Icon

Original Message
Name: Anja2004
Date: January 11, 2004 at 16:10:31 Pacific
Subject: I need help with my skript.
OS: Unix
CPU/Ram: donno
Comment:

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"
done

So 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


Report Offensive Message For Removal

Response Number 1
Name: nails
Date: January 12, 2004 at 15:29:22 Pacific
Subject: I need help with my skript.
Reply: (edit)

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,3

Regards,

Nails


Report Offensive Follow Up For Removal

Response Number 2
Name: frank.gerigk
Date: January 13, 2004 at 02:26:19 Pacific
Subject: I need help with my skript.
Reply: (edit)

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 fun

Frank


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: I need help with my skript.

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software