Which Grep to use a file as input?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Which Grep to use a file as input?
# 1  
Old 10-12-2012
Which Grep to use a file as input?

I have two files: usednaslist & naslist
Using RHEL5

usednaslist
Code:
>filera:/vol/EQIMS/build

>filera:/vol/iquad_dev/FAST_dev

naslist
Code:
>server12 	 SunOS 	 filera:/vol/EQIMS/build 	 /users/uxsrvlogs 	

>servers3 	 SunOS 	 filera:/vol/iquad_dev/FAST_dev 	 /mnt 	

>server4 	 SunOS 	 filerb:/vol/Security 	 /users/em_master

Expected Output is

Code:
>server4 	 SunOS 	 filerb:/vol/Security 	 /users/em_master

What i have tried
Code:
    cat naslist | grep -vf usednaslist
No Output

    cat naslist | egrep -vf usednaslist
No Output

    cat naslist | fgrep -vf usednaslist
No Output

    cat naslist | fgrep -xvf usednaslist
server12 SunOS filera:/vol/EQIMS/build /users/uxsrvlogs

servers3 SunOS filera:/vol/iquad_dev/FAST_dev /mnt

server4 SunOS filerb:/vol/Security /users/em_master


Last edited by Scrutinizer; 10-12-2012 at 02:12 PM.. Reason: code tags instead of quote tags
# 2  
Old 10-12-2012
If you don't have any problem using awk then use..Smilie


Code:
awk 'FNR==NR{gsub(">","",$0);a[$0]=$0;next}{if(! a[$3]){print $0}}' file1 file2

# 3  
Old 10-12-2012
Yeah, those >'s in the one file are going to prevent it from matching directly via grep. It's not a language, you can't tell it 'match part of this regex'. awk is a language, so it can.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies

2. UNIX for Beginners Questions & Answers

How to iterate Grep via all patterns provided in an input file?

When I use the following grep command with options -F and -f, its just displaying the text related to only the last pattern. Command: $ grep -f pattern_file.txt input_file.txt Output: doc-C2-16354 Even the following command yields the same output: Command: $ grep -Ff pattern_file.txt... (6 Replies)
Discussion started by: nsai
6 Replies

3. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

4. Shell Programming and Scripting

Using perl to grep a list of patterns from an input file

I have been struggling to grep a file of NGrams (basically clusters of consonants or Consonant and Vowel) acting as a pattern file from an Input file which contains a long list of words, one word per line. The script would do two things: Firstly read a text pattern from a large file of such... (5 Replies)
Discussion started by: gimley
5 Replies

5. Shell Programming and Scripting

read a file for input and grep in another file

Hi, I'm trying to read a fille into a loop and grep for a string and print the last field of the string in the second file. Then redirect the output to another file but keeping the output in the same order as the original file. I've tried using the following but the ouput from this does not... (3 Replies)
Discussion started by: elmesy
3 Replies

6. 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

7. Shell Programming and Scripting

grep for certain files using a file as input to grep and then move

Hi All, I need to grep few files which has words like the below in the file name , which i want to put it in a file and and grep for the files which contain these names and move it to a new directory , full file name -C20091210.1000-20091210.1100_SMGBSC3:1000... (2 Replies)
Discussion started by: anita07
2 Replies

8. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

9. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

10. Shell Programming and Scripting

How to grep in order based on the input file

Here is an answer rather than a question that I thought I would share. In my first attempt, I was using grep to find a list from file.1 within another file, file.2 which I then needed to paste the output from file.3 to file.1 in the same order. However, the results weren't what I wanted. At... (2 Replies)
Discussion started by: Kelam_Magnus
2 Replies
Login or Register to Ask a Question