Grep multiple string from input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep multiple string from input
# 8  
Old 05-17-2014
Quote:
Originally Posted by Kibou
I had no idea that it could be used as an equivalent of the | operator.
Hope you are not confused with the usage of grep -E and grep -F. Also at any time, you can refer to the man grep
This User Gave Thanks to clx For This Post:
# 9  
Old 05-17-2014
Quote:
Originally Posted by Kibou
Thank you, Don.

I am sorry, I forgot to mention that the string and data files were different files.

I am a little perplexed with the grep -F solution. I had no idea that it could be used as an equivalent of the | operator. Smilie
You still seem to be confused. The -F option to the grep utility has nothing to do with the | extended regular expression special character.

The grep utility searches input files for a list of fixed strings (with the -F option), extended regular expressions (with the -E option), or basic regular expressions (when neither -E nor -F are given). The list can be specified with separate -e options; by a single operand containing the list of expressions on separate lines; by using the -f option to name a file containing strings, BREs, or EREs on separate lines in the file; or by a combination of any or all of the above.

There weren't any BRE or ERE special characters in your sample list of strings to be matched. When that is the case, you can either use fixed strings on separate lines or as separate -e option arguments, or you can convert the fixed strings into an ERE using the | ERE special character to separate the strings in a single ERE. With a large file or with a lot of strings, fixed string searches are likely to be much faster ERE evaluations.

When you see something suggested in these forums that you don't understand, look at the man pages (as clx suggested). If you can't figure out why it worked after reading the man pages, ask us to explain it. We want to help you learn how to use the tools available on UNIX and Linux systems. Note that the utilities available vary from system to system and the options that are available on a given utility also vary from system to system, so when you pose a problem or ask a question, tell us what operating system including the version of that operating system and what shell you're using so we can explain things that will work in your environment.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 05-17-2014
As a Linux sysadmin, I usually read the man pages but it looks like this time I needed extra help.

Your explanation was very helpful, now I understand how it works.

To set some background about myself, long ago I've done some basic shell scripting with bash and then I had to quit for a few years to do more orientated sysadmin tasks. It's kind of frustrating when you realise that you forgot a lot of things. Smilie Now I want to catch up and expand my knowledge. I've also started learning about ksh, which is quite new to me.

Thanks a lot for your concern. I hope to be helpful as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Enhance existing script: Extract Multiple variables & Input in an echo string

Hi Experts I need your help to optimize my script to execute better as I have nearly 1M records & the script is taking close to 40 minutes to execute, so would need support on a faster alternative. Input: file {"house":"1024","zip":"2345","city":"asd","country":"zzv"}... (2 Replies)
Discussion started by: nk1984
2 Replies

2. UNIX for Beginners Questions & Answers

Grep for multiple string

im learning grep and i need some help. i have input word file like this fish map.this is go to.that is i want sed,awk or grep command to extract the following in this format someword SPACE someword.so output will be fish map. go to.Please use CODE tags as required by forum... (11 Replies)
Discussion started by: ahfze
11 Replies

3. Shell Programming and Scripting

Single grep to multiple strings with separate output per string

I need to grep multiple strings from a particular file. I found the use of egrep "String1|String2|String3" file.txt | wc-l Now what I'm really after is that I need to separate word count per each string found. I am trying to keep it to use the grep only 1 time. Can you guys help ? ... (9 Replies)
Discussion started by: nms
9 Replies

4. Shell Programming and Scripting

Multiple Results of Grep in one Line/String?

Hello, I have a Textfile sees like this "Word1":aksdfjaksdf "Word2":askdfjalsdkfdlsjfasldfj "This is Word3":asdfkjalskdfj what i need is a string which sees like this Word1;Word2;This is Word3 Conclusion always the text within "" which is before the : i tried it with grep.... (10 Replies)
Discussion started by: SwordMaster
10 Replies

5. UNIX for Dummies Questions & Answers

Multiple string input in a awk

Hi everybody, I just start my learning about Linux. So, if you can help me, it would be very good ! I have already find the possibility to find the position of a character regular expression in a line with the help of awk : test.txt is : AAAAAGHIJKLAjKMEFJKLjklABCDJkLEFGHIJKL My script is... (2 Replies)
Discussion started by: thewizarde6
2 Replies

6. Shell Programming and Scripting

Multiple results as input to grep or awk

Hi: This is my first post in this forum. apologies if I am asking question that has been asked here multiple times. I wrote a python script that prints list of identifiers. I have another file notoriously big and with no particular format. I plan to search the identifiers in this file... (2 Replies)
Discussion started by: oriolebaltimore
2 Replies

7. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

8. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

9. UNIX for Dummies Questions & Answers

how to use grep: finding a string with double quotes and multiple digits

I have a file with a lot of lines (a lot!) that contain 10 digits between double quotes. ie "1726937489". The digits are random throughout, but always contain ten digits. I can not for the life of me, (via scouring the internet and grep how-to manuals) figure out how to find this when I search.... (3 Replies)
Discussion started by: titusbass
3 Replies

10. UNIX for Dummies Questions & Answers

Regex to match when input is not a certain string (can't use grep -v)

Hey everyone, Basically, all I'm looking for is a way to regex for not a certain string. The regex I'm looking to avoid matching is: D222 i.e. an equivalent of: awk '!/D222/' The problem is that I use this in the following command in a Bash script: ls ${source_directory} | awk... (1 Reply)
Discussion started by: kdelok
1 Replies
Login or Register to Ask a Question