Results 1 to 5 of 5
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 ...
- 06-21-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 4
Help with Grep
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.
- 06-21-2007 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:awk -F"," '{print $2}' file
- 06-21-2007 #3Just Joined!
- Join Date
- Jun 2007
- Posts
- 4
Thanks a lot.
Regards,
Arul.
- 06-21-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Or:
RegardsCode:cut -d"," -f2 file
- 06-22-2007 #5
For posterity's sake, here is a grep way to do it.
It assumes that your data contains one or more numerics, followed by a dot (.), followed by one or more numerics. You have to know your data in order for this to work correctly.Code:[hal@troy ~]$ cat some-file Student Id,10261.15147,Course,157 Student Id,102.10147,Course,15 [hal@troy ~]$ grep -o '[0-9]\{1,\}\.[0-9]\{1,\}' some-file 10261.15147 102.10147
The -o option only selects the matching expression as you probably know.


Reply With Quote