Fgrep literal string from a file

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Fgrep literal string from a file
# 1  
Old 01-16-2017
Fgrep literal string from a file

have a file1
Code:
aaa-bbb-ccc-abcd
aaa-bbb-ccc-bacd
aaa-bbb-ccc-aaad
aaa-bbb-ccc-a

have another file2
Code:
aaa-bbb-ccc-a file

using the fgrep command, trying to have only the literal string returned.

Code:
fgrep -f file2 file1

is returning
Code:
aaa-bbb-ccc-abcd
aaa-bbb-ccc-aaad
aaa-bbb-ccc-a

Only looking for
Code:
aaa-bbb-ccc-a

any ideas?
# 2  
Old 01-17-2017
Quote:
Originally Posted by jimmyf
have a file1
Code:
aaa-bbb-ccc-abcd
aaa-bbb-ccc-bacd
aaa-bbb-ccc-aaad
aaa-bbb-ccc-a

have another file2
Code:
aaa-bbb-ccc-a file

using the fgrep command, trying to have only the literal string returned.

Code:
fgrep -f file2 file1

is returning
Code:
aaa-bbb-ccc-abcd
aaa-bbb-ccc-aaad
aaa-bbb-ccc-a

Only looking for
Code:
aaa-bbb-ccc-a

any ideas?
The literal string aaa-bbb-ccc-a file that is in file2 does not appear anywhere in file1. Why do you think there should be any output???

If file2 contained:
Code:
aaa-bbb-ccc-a

instead of:
Code:
aaa-bbb-ccc-a file

then the command:
Code:
fgrep -x -f file2 file1

or:
Code:
grep -Fx -f file2 file1

should do what you want.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to avoid "Too many arguments" error, when passing a long String literal as input to a command?

Hi, I am using awk here. Inside an awk script, I have a variable which contains a very long XML data in string format (500kb). I want to pass this data (as argument) to curl command using system function. But getting Too many arguments error due to length of string data(payloadBlock). I... (4 Replies)
Discussion started by: cool.aquarian
4 Replies

2. Shell Programming and Scripting

Reading a long literal continued next line

I am trying to identify all messages or prompts from a number of COBOL programs and they can usually be identified by a pair of double quotes on one line. However, sometimes the literal will not be finished on the first line but after a dash in column 7 of the next line, the literal will be... (6 Replies)
Discussion started by: wbport
6 Replies

3. Shell Programming and Scripting

Fgrep/grep -f and literal strings

I have a file like this: cat file name = server jobname = 1010 snapshot_name = funky_Win2k12_20140213210409 I'm trying to use grep to isolate that first line (name = server), but grep -f "name = " file as well as fgrep "name = " file returns all 3 lines. How do I return... (1 Reply)
Discussion started by: ampsys
1 Replies

4. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

5. UNIX for Dummies Questions & Answers

sed containing $ as literal and variable

Hi, i have a data file cat f1.txt $V01$S this is 1 $v02$D this is 2 $v03$F this is 3 I have a variable $PARM which contains value say 'V01' I have to print lines from f1.txt that start with '$'<${PARM}>'$' How do i get matching lines from f1.txt that start with '$' then with ${PARM}... (1 Reply)
Discussion started by: ysrini
1 Replies

6. Shell Programming and Scripting

how do i print literal value?

hi guys!!! i wanna print literal value itself. for example, mycommand=$( ls -ltr ) "echo $mycommand" is not working... it runs the "ls" command. also "echo $"mycommand" " is not working either. it print out "mycommand" literally... how can i print out " ls -ltr " using variable "mycommand"? (4 Replies)
Discussion started by: curtis911
4 Replies

7. Shell Programming and Scripting

Problem in Using fgrep Command with pattern file option

Hi, i am using fgrep command with following syntax fgrep -v -f pattern_file_name file file contains few line and have the pattern which i am giving in pattern file. My Problem is : its is not giving any output. while i am using fgrep -f pattern_file_name file it is showing all... (4 Replies)
Discussion started by: emresearch
4 Replies

8. Shell Programming and Scripting

Bash: Reading out rows of a file into a dynamic array and check first literal

Hello, i have a file "Movie.ini" looking e.g. like follows * MOVIE A bla bla MOVIE B blubb blubb MOVIE C I'd like to read the file "Movie.ini" with cat and grep and check whether it includes the string MOVIE only with a '*' at the beginnig. By doing "cat Movie.ini| grep MOVIE... (14 Replies)
Discussion started by: ABE2202
14 Replies

9. Shell Programming and Scripting

fgrep to file plus some

Hi, I know that I can grep desired data to a file but is there a way to add an additional field of data to the output in addition to what is found. I want to add a login id to the data that is found in the grep. Is this even possible? Thanks for your help. Toni (14 Replies)
Discussion started by: ski
14 Replies

10. Shell Programming and Scripting

How to scan a file for literal, return 0 or 1 if found?

How can i scan a file in a UNIX script and look for a particular keyword? For example if i wanted to scan the file "lpcmp165.out" and see if it contains the term "error" or "ERROR" and then return a 0 or 1 or some indicator as such? Detail example: sqlplus -s xx/yyyyyyy#@zzz <<EOF >... (11 Replies)
Discussion started by: bobk544
11 Replies
Login or Register to Ask a Question