How to handle grepping variable data containing wildcards?
I have a lot of files with keywords and unique names. I'm using a shell script to refer to a simple pattern file with comma separated values in order to match on certain keywords. The problem is that I don't understand how to handle the wildcard values when I want to skip over the unique names.
Here is an example of the data patterns in the files:
An example of the pattern file:
The shell script operates like this:
The result looks like this:
[matches]
[no matches]
I get correct matches on the patterns that do not use a wildcards, so I know the script is working in that respect.
The wildcard patterns do not work, and it looks like the wildcards themselves are getting mangled somehow. In this example, the pattern has changed from "abcd mnop .* efgh ijkl" to "abcd mnop . .. efgh ijkl"
Thanks
Last edited by Scrutinizer; 10-10-2016 at 02:20 PM..
Reason: additional code tags for data samples
The script snippet looks garbled. It sounds like the wildcard in the pattern got expanded by the shell at some point. You need more double quotes where it happens
But aren't you making it too complicated? How about
Juha
This User Gave Thanks to Juha Nurmela For This Post:
You got me looking back at the quotes again and I found the problem where I initially strip out the fields I need for the pattern. What a dumb mistake!
Yes, I should try to make it simpler.
Thanks!
I appreciate the suggestion. I need the labels for characterizing data in the output, so I'm hanging onto those until I get into the loop where I then separate them and use them both. Also, I'm doing additional things inside the while loop that I didn't include in the post.
The main point of my post was to find out why I wasn't able to get wildcards to work properly. I wasn't expecting to find out that I had overlooked quoting the variable, so I included the other information because I thought it might be helpful for resolving the problem.
Anyway, thanks again for the suggestion! I may use it for another project.
The problem of your snippet in post#1 - beyond the missing do in the while loop - is that the awks in the two "command substitutions" read from stdin and thus drain the pattern file. As it has just two lines, when it comes to assigning fp its already at EOF, fp is empty, and thus grep looks for an empty match.
With sth. like
you should come close to what you need.
Im trying to search for a single variable in the first field and from that output use awk to extract out the lines that contain a value less than a value stored in another variable. Both the variables are associated with each other.
Any guidance is appreciated.
File that contains the... (6 Replies)
Dear Forum members,
I am having trouble getting the complete filename (and directory path) in a variable.
Output directory mentioned in the code have three files:
DISPLAY_CITY_DETAILS_15-05-2019-08-29-26_MIGRATE_london.out
DISPLAY_CITY_DETAILS_15-05-2019-08-29-26_MIGRATE_paris.out... (4 Replies)
Hi There, Good Day !!
I have txt file containing data in the below format. There are many lines, here i have mentioned for example.
cat remo.txt
2/3/2017 file1
3/4/2016 file2
6/6/2015 file5
1/1/2018 file3
4/3/2014 file4
-
-
-
I need to grep the file names for given date rage... (11 Replies)
Hello,
I have a data in file 1
2000000024776
2000000026979
2000000033355
2000000036309
2000000041291
2000000042679
2000000067221
and in file 2 its like this
2000000024776 16
2000000026979 16
2000000033355 16 (2 Replies)
I have a script which reads a number out of a log file. The pertinent line is this:
cat /tmp/listofnumbers
When I run cat /tmp/listofnumbers what I am seeing is on each line.
I am trying to make the script read from that file and grep for a variable like the following line should do:
... (4 Replies)
Hello,
I have a text file which contains a list of strings which I want to grep from another file where these strings occur and print out only these lines.
I had earlier used the grep command
where File1 was the file containing the strings to be grepped (Source File) and File2 the Target File... (4 Replies)
Hi,
I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input.
I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (0 Replies)
Hello,
I would like for the user to input the date for a particular log file, then have the input sent to a variable, which is then used via grep to extra the logs for the specific date the user request.
I did some searching, but I still don't understand why I'm not seeing any result.
... (4 Replies)
I need to pass a parameter that will then be grepped.
I need it to grep /paramater and then have a space
so if 123 was passed my grep would be grep '/123 ' sample.log
this works fine from the command line
but when i try and set it searchThis="/$2 "
and then run grep $searchThis... (6 Replies)
Is there anyway you can grep using multiple wildcards? When I run the below line the results return fine;
grep 12345 /usr/local/production/soccermatchplus/distributor/clients/*/out/fixtures.xml | awk -F/ '{print $8}'
However ideally, I need it to grep for;
grep 12345... (3 Replies)