LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-03-2012, 02:47 AM   #1
arn2025
LQ Newbie
 
Registered: Feb 2012
Posts: 26
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 02-03-2012, 03:02 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
1 members found this post helpful.
Old 02-03-2012, 03:02 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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

Last edited by Dark_Helmet; 02-03-2012 at 03:03 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SuSE 9.3 - searching for specific text in file - Command line options? EnderX Linux - Newbie 1 04-15-2010 02:45 PM
Q: Searching text within a file WITHOUT regular expressions stormcloud Linux - General 1 07-30-2009 05:41 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 03:36 PM
text searching sopiaz57 Linux - Software 4 06-02-2005 02:00 PM
Searching a text file - complicated cyph3r7 Linux - General 2 12-16-2003 11:45 AM


All times are GMT -5. The time now is 06:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration