-1

Just started learning Linux. Getting my hands dirty with grep and gawk.

Suppose I want to print all the available names in .txt file or for example I have text file that goes;

"blah blah blah blah blah

blah bhah blah blah blah

Joe

Allen

David

John

blah blah blah blah blah " 

Now I would like to print all the names found in the text file only. How would I go about doing it? What will my syntax be?

Jahid
  • 21,542
  • 10
  • 90
  • 108
  • 2
    What does your input look like, exactly? Your output? What have you tried so far? Have you proof-read your question title? This is all not very clear to me. – Benjamin W. Jan 29 '16 at 06:48
  • Sorry about that. please check the question again, I made some changes to make things clearer. I think ill be needing a gawk script but sadly I have no idea how to go about it. thanks for the reply. – Novel Mathhews Jan 29 '16 at 07:33
  • gawk '/Joe/{print $0}' Input.txt The above simple command helps me print Joe but i am unable to add other names to the same single command. Also is there any other way to do it ? – Novel Mathhews Jan 29 '16 at 11:22
  • 1
    Please read [ask] and [mcve] – glenn jackman Jan 29 '16 at 11:46

1 Answers1

0

Having a file "names" with all the names you're looking for, one per line:

 Allen
 David
 Joe
 ...

Then search of any of those lines:

grep -f names thefiles

You might need to add the option -F (the lines in the file "names" are strings, and not regex-en) or option -w (the match must be a word, not part of word) as well, or the option -o (print only the match, instead of the line).

PBI
  • 335
  • 1
  • 4