-   Linux - General (
-   -   how to extract ascii separated values in a text file? (

depam 01-24-2012 11:34 PM

how to extract ascii separated values in a text file?

I have one file consisting of lines which has some info separated by "|". I want to grep the file and provides me a list of records on the 3rd, 4th entry on a single line. How will this be possible? I am guessing should be using "sed" but not an expert. Also wondering if you can provide me a good reference for logs and values manipulation. Thanks.

flamelord 01-25-2012 12:59 AM

Do you mean the 3rd and 4th fields on the records that get through grep?

That could be achieved with:

grep <whatever> | cut -d'|' -f3,4
it could also be down in awk with something like:


awk -F'|' '/pattern/ {$3, $4}'
sed could do it too, but I think that would be a little more complicated.

chrism01 01-25-2012 01:08 AM

Given file t.t



awk '{print $3,$4}' FS="|" t.t
c d
e r


depam 01-26-2012 11:31 PM

Thanks guys...Now another complicated thing is that inside the file, there are few texts and this information is in the middle of the line.


some text some text [A|B|C|D] some text some text

I want to check the pattern "II" in that line and output only those lines with that content and if possible only those starting with "[" and ending with "]".


flamelord 01-27-2012 01:43 AM

I think something like


sed -e '/II/ s/.*\[\(.*\)\].*/\1/p' -n <file>
would work

All times are GMT -5. The time now is 08:00 AM.