GREP Problem with Search Values


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers GREP Problem with Search Values
# 1  
Old 05-11-2012
GREP Problem with Search Values

Hello All,

I'm using the following command:

Code:
grep -F -f List.csv Data.csv > Output.csv

List.csv
Code:
aa
bb
cc
dd

Data.csv
Code:
aa,other stuff
zz,other stuff
bb,other stuff
aa_2,other stuff
dd,other stuff
dd_2,other stuff

output.csv
Code:
aa,other stuff
bb,other stuff
aa_2,other stuff
dd,other stuff
dd_2,other stuff

The issue that I'm having is that the output is returning things like aa_2 when i don't want it to. I just want aa,other stuff.
# 2  
Old 05-11-2012
Try:
Code:
sed 's/.*/^&,/' file1 | grep -f- file2

or
Code:
awk 'NR==FNR{A[$1]; next} $1 in A' file1 FS=, file2

# 3  
Old 05-11-2012
Thanks for the reply.

I'm creating my program in Perl, and i can't seem to get the following code to run.

Code:
awk 'NR==FNR{A[$1]; next} $1 in A' file1 FS=, file2

It looks like it doesn't like the $1

Code:
awk: NR==FNR{A[]; next}  in A
awk:           ^ syntax error
awk: fatal: invalid subscript expression

the code in my program is as follows:

Code:
qw("awk 'NR==FNR{A[$1]; next} $10 in A' $filePortfolios FS=, $fileIn > $fileTemp");


Last edited by WongSifu; 05-11-2012 at 12:41 PM.. Reason: adding orginal code
# 4  
Old 05-11-2012
Hi, like this the single quotes are within double quotes and therefore no longer protect $1 and $10 from expansion by the shell, you would need to escape them...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

Pattern search and modify the values

I have one file and the file may contain 500 to 15,000 records. I need to search pattern ^F509= and then increment the corresponding value by one and print the entire line. Please note that Its not a fixed length file. Can anyone please help? ex: ^F509=204656 ^F509=204656 ... (6 Replies)
Discussion started by: vinus
6 Replies

4. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

5. UNIX for Advanced & Expert Users

Search and replace a array values in perl

Hi, i want to search and replace array values by using perl perl -pi -e "s/${d$i]}/${b$j]}" *.xml i am using while loop for the same. if i excute this,it shows "Substitution replacement not terminated at -e line 1.". please tell me what's wrong this line (1 Reply)
Discussion started by: arindam guha
1 Replies

6. Programming

Binary Search Tree Search problem

I am writing code for a binary search tree search and when I compile it i am getting strange errors such as, " /tmp/ccJ4X8Xu.o: In function `btree::btree()': project1.cpp:(.text+0x0): multiple definition of `btree::btree()' " What does that mean exactly? tree.h #ifndef TREE_H #define... (1 Reply)
Discussion started by: meredith1990
1 Replies

7. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

8. Shell Programming and Scripting

Search values between ranges in File1 within File2

Hi people, I have 2 files, one with a list of non consecutive ranges (File1.txt), where each range begins with the value in column 1 and finishes with the value in column 2 in the same line, as can be seen above. 215312581156279 215312581166279 215312582342558 215312582357758... (4 Replies)
Discussion started by: cgkmal
4 Replies

9. UNIX for Dummies Questions & Answers

problem with grep on search string in a txt file over multiple files

I have a couple of things I got stuck on 1) I have a text file containing 25k search string that I need to search against compressed file. I have used this command but somehow it doesn't seems to use all the search terms. I have put one search string per line in the txt file (I clean up... (2 Replies)
Discussion started by: m00
2 Replies

10. Shell Programming and Scripting

Search list of values

I have a file which contains a list of search values $cat my.txt FTIP002671604 FTIP002702940 FTIP002703183 FTIP002414805 And lots of such search values. I have to search these valus in the current directory. Can we do this one command wihtout writing a script. Regards, Rahul. (1 Reply)
Discussion started by: rahulrathod
1 Replies
Login or Register to Ask a Question