LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-04-2008, 02:56 PM   #1
cgcamal
Member
 
Registered: Nov 2008
Location: Tegucigalpa
Posts: 72

Rep: Reputation: 16
Get all lines containing 23 specific words with AWK



Hi guys,

How can I do an extraction of all lines that contain 23 strings in the file with awk?

I tried with awk 2 words,

Code:
awk '/word1//word2/' source.txt > filtered.txt
but putting the 23 words of interest for me, like below in one line itīs not processed, I get a "bip" sound.
Code:
awk '/word1//word2//.....//word22//word23/' source.txt > filtered.txt

Thanks for any suggestion.
 
Old 11-04-2008, 04:37 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Put the 23 words in a file - wordfile - one word on each line
Code:
grep -f wordfile inputfile
 
Old 11-04-2008, 04:56 PM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
When I try:
Code:
awk '/word1//word2/' testfile
I get an error message.

When I try:
Code:
awk '/word1/||/word2/' testfile
It works as I expected, matching word1 or word2

If you have commonality in your words, eg:
Code:
awk '/word/&&/6/' testfile
This would match any line that contained both "word" and "6"

Matching:
word6
word06
word16


Would also match:
Why are we drawn to word of the 6?

EDIT:- See Jim's answer!

could also use a file for awk:

awkward_list:
Code:
/word1/
/word2/
/word3/
Code:
 awk -f awkward_list testfile

Last edited by Disillusionist; 11-04-2008 at 05:00 PM. Reason: Spent too long composing my thoughts!
 
Old 11-05-2008, 11:51 AM   #4
cgcamal
Member
 
Registered: Nov 2008
Location: Tegucigalpa
Posts: 72

Original Poster
Rep: Reputation: 16
Many thanks guys,

Trying your different answers Iīve learned many things. Testing
and testing got what I need.

Thanks again
 
  


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
Awk Question to search specific strings grouped by blank lines rk4k Programming 6 07-08-2008 12:56 AM
Delete specific Range of lines Using sed , awk, grep etc. joyds219 Linux - Newbie 4 03-28-2008 09:59 AM
Replacing text on specific lines with sed or awk? Lantzvillian Linux - Newbie 5 10-17-2007 10:00 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 10:19 AM


All times are GMT -5. The time now is 01:12 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration