Kenny,

Thank you for your suggestion.

The following line works:
grep univ abc.txt | cut -f3 -d, >> dev.txt.


While the following line intended to remove quotes does NOT work:
grep univ abc.txt | cut -f3 -d, | sed s/\"//g >> dev.txt
It resulted in a line starts with ">" prompt, and not output dev.txt

Could you please double-check or modify it?

Also, if one column is missing, and "," is used to indicate that missing column, like the following (2nd column of 3rd line is missing):

"name","age","school"
"jerry" ,"21","univ of Vermont"
"jesse",,,"Dartmouth college"
"jack","18","univ of Penn"
"john","20","univ of south Florida"

Does the "cut" approach still apply? If not, what command would you suggest to address this missing issue?

Thank you again.
Zhao


[EMAIL PROTECTED] wrote:
Actually, if you are looking for only lines that contain the string "univ", 
then you would want to grep for it:

grep univ abc.txt | cut -f3 -d, >> dev.txt.

Paul's example would give you the third field of each line, even if they don't have 
"univ" in them. Now, if you wanted to remove the quotes, then you would need 
something like:


grep univ abc.txt | cut -f3 -d, | sed s/\"//g >> dev.txt
FYI,
Kenny

 -------------- Original message ----------------------
From: "Whelan, Paul" <[EMAIL PROTECTED]>
Like so: cat abc.txt | cut -d, -f3

Thanks.

-----Original Message-----
From: Zhao Peng [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 10, 2006 11:51 AM
To: gnhlug-discuss@mail.gnhlug.org
Subject: extract string

Hi

Suppose that I have a file called abc.txt, which contains the following 5 lines (columns are delimited by ",")

"name","age","school"
"jerry" ,"21","univ of Vermont"
"jesse","28","Dartmouth college"
"jack","18","univ of Penn"
"john","20","univ of south Florida"

My OS is RedHat Enterprise, how could I extract the string which contains "univ" and create an output file called def.txt, which only has

3 following lines:

univ of Vermont
univ of Penn
univ of south Florida

Please suggest the simplest command line approach.

Thank you.
Zhao
_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss

_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss




_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss

Reply via email to