Topic
  • 2 replies
  • Latest Post - ‏2007-08-16T02:53:22Z by James.Zhu
arul_anand_2000@yahoo.com
1 Post

Pinned topic Script Help

‏2007-06-21T16:38:41Z |
Hi All,

I am trying to extract the values of Student Id information from the file which 1000 of lines of information as below

Student Id,10261.15147,Course,157
Student Id,102.10147,Course,15

Output should be
10261.15147
102.10147

I am struggling to do this. As this is my first exp. in doing Shell script.

I did an grep -o ',0-9.0-9,' filename

i was able to get the following output

,10261.15147,
,102.10147,

But was not able to remove the , in start and end of each line. Can anyone help me to do this.

Thanks in Advance.

Regards,
Arul.
Updated on 2007-08-16T02:53:22Z at 2007-08-16T02:53:22Z by James.Zhu
  • SystemAdmin
    SystemAdmin
    232 Posts

    Re: Script Help

    ‏2007-07-17T14:53:28Z  
    you can use cut command

    cut -f2,3 -d"," <filname>
  • James.Zhu
    James.Zhu
    1 Post

    Re: Script Help

    ‏2007-08-16T02:53:22Z  
    cat data |awk -F "," '{print $2}'

    OR

    perl -e '
    open(FH,"data")||die "ERROR $!";
    while(<FH>){
    next unless(/\,(\d+\.\d+)\,/);
    print $1."\n";
    }
    '