LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   searching a text file (https://www.linuxquestions.org/questions/linux-newbie-8/searching-a-text-file-927342/)

arn2025 02-03-2012 01:47 AM

searching a text file
 
i have a text file and i want to search for lines with 8, 9, and 2 in the second column.
778560717,1,0.000000
778560717,2,0.000000
778560717,3,0.000000
778560717,4,0.000000
778560717,5,0.000000
778560717,6,0.000000
778560717,7,0.000000
778560717,8,0.000000
778560717,9,0.000000
778560717,31,0.000000
778560717,32,250.000000
778560717,39,0.000000

evo2 02-03-2012 02:02 AM

Hi,

in the general case, awk might be more useful, but in this case you can use grep and exploit the fact that only the 2nd column has a ',' on either side.

Code:

grep -E ',[8|9|2],' filename
Cheers,

Evo2.

Dark_Helmet 02-03-2012 02:02 AM

What have you tried so far? The grep, sed, and awk commands are all capable of handling something like this.

EDIT:
Well, since the cat is out of the bag... :)
Code:

sed -n '/[^,]*,[289],/p' datafile.txt


All times are GMT -5. The time now is 06:39 PM.