Grep solution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep solution
# 1  
Old 04-27-2007
Grep solution

I have a file arg_file
a1, b1, c1...
a2, b2, c2...
a3, b3, c3...
a4, b4, c4...
a5, b5, c5...
a6, b6, c6...
a7, b7, c7...
a8, b8, c8...
a9, b9, c9...

I have another file pat_file
a2
a5
a9

I want to create an output file which does not contains the values found pat_file :
a1, b1, c1...
a3, b3, c3...
a4, b4, c4...
a6, b6, c6...
a7, b7, c7...
a8, b8, c8...

Currently I am using `grep -v -f pat_file arg_file > outputfile`. But this is taking very long to process ..is there an efficient soultion to this.
My files may contain peak time approx. 90K records too.

Thanks
Amruta
# 2  
Old 04-27-2007
how about this

Code:
awk -F, 'NR==FNR{arr[$1]=$0} NR!=FNR{arr[$1]=""} END{for(i in arr) if(arr[i]!="") print arr[i]} filename1 filename2
filename1 --> file with all the data (arg_file)
filename2 --> file with columns that needs to be removed (pat_file)

# 3  
Old 04-27-2007
Code:
awk -F"," ' FNR == NR { arr[$0]=1; next } !arr[$1] ' pat_file arg_file

# 4  
Old 05-03-2007
using join

Code:
join -t, -1 1 -v 1 arg_file pat_file

Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. UNIX for Dummies Questions & Answers

Awk/sed solution for grep,cut

Hi, From the file "example" with lines like below, I need the int value associated with ENG , i.e, 123 SUB: ENG123, GROUP 1 SUB: HIS124, GROUP 1 .. .. Normally , i do grep ENG example | cut -d ' ' -f 2 | cut -c 4-6 Is it possible to do it in simpler way using awk/sed ? ... (5 Replies)
Discussion started by: priyam
5 Replies
Login or Register to Ask a Question