Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract rows based on the coulmn values..

Status
Not open for further replies.

kumariaru

IS-IT--Management
Mar 9, 2006
61
AU
Hi All..
Good morning...I like know to how can I find out rows based on a condition. I have something like this: My file is of 2Gb size..I need to check data with this file based on the certain columns.This is a comma separated file..I want to get the complete row when there is match and also all the rows.I know we can work with the grep and sed and awk.. but I am not sure of the expressions to put..
Can anyone give my an idea how can I can get all rows based on the 5 cloumn values...This is a huge file ..I can nt check it manually....

Thanks a lot...
 
A starting point (all rows having a letter A in the 5th column):[tt]
awk '$5=="A"' /path/to/input > output[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

Hmm... The simple way woul look like :
Code:
sed -n '/^\([^,]*,\)\{4\}[green][i]whatever[/i][/green],/p' /input/file

[gray]# or[/gray]

awk -F, '$5="[green][i]whatever[/i][/green]"' /input/file
But that file is huge. [tt]perl[/tt] precompiles the code so would be faster. Beside this, another speedup would be to meke rough check for the line, and only after to split it up.
Code:
perl -ne 'if (index $_,",[green][i]whatever[/i][/green],"!=-1) { @f=split /,/; print $_ if $f[4] eq "[green][i]whatever[/i][/green]"}'
But even better would be to load the data into a database and create an index on the fifth field.

Feherke.
 
Hi PHV,
I tried using the above expression given by you..but i am not able to get the output. I am doing something like this;

awk '$2=='7890'" file1.dtl > file2.dtl

I am not getting the wanted answer, it is empty...

Thank you..
 
OOps, I missed the -F',' stuff:
Code:
awk -F',' '$2=="7890"' file1.dtl > file2.dtl

Note: pay attention on single and double quotes !


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi Feherke,
These columns are keys...I have tried using the above expressions but I do not why I am not able to figure them...Any thing else I need to do..

Thank you
 
Hi

I checked all three solutions before posting, so I am sure they work. Is possible that the [tt]sed[/tt] will not work on your machine as it needs GNU [tt]sed[/tt]. The [tt]perl[/tt] solution unfortunately lacks the filename from the end of the line, but otherwise works.
kumariaru said:
Any thing else I need to do..
If you get errors, then paste those messages here.

Feherke.
 
Kumariaru, if you post a sample of the data and the desired output from that sample it would help immensely.

Annihilannic.
 
Hi All..
I have used sed expression and it is working fine.Sorry for not posting the warnings and for replying late..

Thank you..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top