-------------- Original message ----------------------
From: Zhao Peng <[EMAIL PROTECTED]>
> 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?

I have checked it, and it works exactly as it should. 

> 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?
> 

A column is not missing, it is just empty. It is still delimited by a ",", so 
it is still a valid column. However, in the example above, there is an extra 
column in the 3rd line. All of the other lines have "name,age,school". Line 3 
has "name,empty,empty,school".

Now, if you know that the school is always going to be the last field, you may 
not want to use cut at all. You might want to use something like :

grep univ abc.txt | awk -F, '{print $NF}'| sed 's/\"//g'

awk takes the place of `cut` in this case by looking at the last field 
delimited by a ",".

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

Reply via email to