I am trying to grep a variable with multiple lines with multiple patterns
below is the pattern list in a variable called "grouplst", each pattern is speerated by "|"
I need to use the patterns above to grep a variable with multiple lines inside. the variable with the multiline content is called "nidgrps", content of the variable is below
I tried using egrep but it didnt work, my code is below
I am trying to grep a variable with multiple lines with multiple patterns
below is the pattern list in a variable called "grouplst", each pattern is speerated by "|"
I need to use the patterns above to grep a variable with multiple lines inside. the variable with the multiline content is called "nidgrps", content of the variable is below
I tried using egrep but it didnt work, my code is below
"rptfile" is where I want the greped output to go
Thank You
When you have code that isn't working, it always helps us help you if you show us the exact diagnostics that are printed when you run your code, show us any other output that you get, and tell us what operating system and shell you're using.
Assuming that the variable nidgrps has been initialized to the name of the file containing the data you want to process, that the variable rptfile has been initialized to the string rptfile, that you are trying to perform a case-insensitive match, that you want to add the matched text to the end of the current contents of the file named rptfile rather than replace its existing contents, and that you are using a shell that uses basic Bourne shell syntax; you would have succeeded if you had quoted your variables appropriately.
But, in addition to that, there is no need for cat in this pipeline; using it just slows you down and consumes system resources needlessly. Try:
Consider the following... it works. I'm thinking that just like my case below your nidgrps maybe is a string inside a variable?? So you'd use echo instead of cat??
I am able to grep multiple patterns which stored in a files. However, how could we replace the whole line with either the pattern or new string?
For example:
pattern_file: *Info in the () is not part of the pattern file. They are the intended name to replace the whole line after the pattern... (5 Replies)
job_count=`grep -e "The job called .* has finished | The job called .* is running" logfile.txt | wc -l`
Any idea how to count those 2 patterns so i have a total count of the finished and running jobs from the log file?
If i do either of the patterns its works okay but adding them together... (8 Replies)
Hi,
I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command.
Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns.
Xargs -I {} grep... (3 Replies)
I have a file with many rows.
I want to grep for multiple patterns from the file.
For eg:
XX=123|YY=222|ZZ=566
AA=123|EE=222|GG=566
FF=123|RR=222|GG=566
DD=123|RR=222|GG=566
I want the lines which has both XX and ZZ.
I know I can get it like this.
grep XX file | grep YY
But... (10 Replies)
Hi,
I want to list the files containing a no of pattern
like for single string i can use
grep -l "string" *
This command will enlist the files containg this string. Similarly i would like to use for multiple string.
I like to enlist file names having string1 and string 2
Can... (3 Replies)
Guys,
i used egrep "pattern1|pattern2". But the whole word is searched. But i want the output if only the exact word is matched. i.e the output is got evenif a part of the pattern is matched.
I tried the -w opion but its showing usage error.
Please help me out on this one. please sent me... (2 Replies)
Hii... Every One......
I want to grep multiple patterns with space in between them.
For eg : I have a file which contains following :
red cat
every one
new one
you are
an ox
take one
Now, what I want to do is to grep " you are" , "an ox" and "red cat" from this file.
Any help........ (5 Replies)
Hi All,
I have a file. I need to find multiple patterns in a row and need those rows to divert to new file.
I tried using grep -e / -E / -F options as given in man.
But its not working.
==> cat testgrep.txt
william,fernandes,xxxxx
mark,morsov,yyyy
yy=,xx=
yyyy=,xxxx==
==>... (7 Replies)
Hi,
Can we grep multiple patterns in UNIX.
for example:
cat /x/y/oratab | grep -i "pattern1|pattern2" .... etc
I require the syntax for multiple patterns. | is not working as I explained in example.
Malay (4 Replies)
I want to get a list of all the files in the current directory that have two patterns. I can do first grep of one pattern and then with the output do the grep of the second pattern.
if the output of 1st pattern search results in many files, it is very difficult to do a grep of the 2nd pattern for... (1 Reply)