Fgrep/grep -f and literal strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fgrep/grep -f and literal strings
# 1  
Old 02-17-2014
Fgrep/grep -f and literal strings

I have a file like this:

cat file
Code:
name = server
jobname = 1010
snapshot_name = funky_Win2k12_20140213210409

I'm trying to use grep to isolate that first line (name = server), but
Code:
grep -f  "name = " file

as well as
Code:
fgrep "name = " file

returns all 3 lines. How do I return results LITERALLY as I'm quoting them without it including matches that have preceding text?

---------- Post updated at 03:17 PM ---------- Previous update was at 03:11 PM ----------
*Edit - Might've answered my own question....seems that '^' works.

i.e. -
Code:
grep "^name = " file

# 2  
Old 02-17-2014
Hi.

Assume z4 contains:
Code:
name = server
jobname = 1010
snapshot_name = funky_Win2k12_20140213210409

then:
Code:
$ fgrep -w "name =" z4
name = server

For:
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
fgrep GNU grep 2.5.3

See man fgrep for details.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Fgrep literal string from a file

have a file1 aaa-bbb-ccc-abcd aaa-bbb-ccc-bacd aaa-bbb-ccc-aaad aaa-bbb-ccc-ahave another file2 aaa-bbb-ccc-a fileusing the fgrep command, trying to have only the literal string returned. fgrep -f file2 file1 is returning aaa-bbb-ccc-abcd aaa-bbb-ccc-aaad aaa-bbb-ccc-aOnly looking for... (1 Reply)
Discussion started by: jimmyf
1 Replies

2. Shell Programming and Scripting

Grep for strings

Hi, Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36 How can I grep for the strings chrome and safari from a file, and if chrome print Chrome/40.0.2214.94 to a file and also count the number of times chrome is found? ... (4 Replies)
Discussion started by: cyberfrog
4 Replies

3. Shell Programming and Scripting

Grep process with two strings

Hi, I am trying to get the PID of a process that is defunct. I have two quesitons on this. 1) how do I pass in two strings? This is what I am using now: ps -ef |egrep -i "programname|<defunct>" But this returns multiple results with the word defunct in them. 2) How do I make it so that... (1 Reply)
Discussion started by: ChickenPox
1 Replies

4. Programming

How to hide from UNIX strings - obfuscate or hide a literal or constant?

Hi, I need to somehow pipe the password to a command and run some SQL, for example, something like echo $password | sqlplus -s system @query01.sql To make it not so obvious, I decided to try out writing a small C program that basically just do echo $password. So now I just do x9.out | sqlplus... (8 Replies)
Discussion started by: newbie_01
8 Replies

5. Shell Programming and Scripting

Grep 2 same strings in a same line??

I have this code TrackingId:1362412470675;MSISDN:; INFO - number of clietns:3:Received response is: EMSResponse , protocolVersion=5, purchaseOptions=null, serviceData=ServiceData , screenData=CanvasData ]], title=null, titleResource=MessageResource], screenType=null]], serviceId=idBamboo,... (7 Replies)
Discussion started by: nikhil jain
7 Replies

6. Shell Programming and Scripting

Can't grep multiple strings

I have a script that periodically checks the Apache error_log to search for a specific error that causes it to hand and, if found, it restarts the service. I recently found another error that forces it to hand and won't serve pages until it is reset. What I'm trying to do is to get the script to... (3 Replies)
Discussion started by: cfjohnsn
3 Replies

7. Shell Programming and Scripting

grep/fgrep/egrep for a very large matrix

All, I have a problem with grep/fgrep/egrep. Basically I am building a 200 times 200 correlation matrix. The entries of this matrix need to be retrieved from another very large matrix (~100G). I tried to use the grep/fgrep/egrep to locate each entry and put them into one file. It looks very... (1 Reply)
Discussion started by: realwindfly
1 Replies

8. Shell Programming and Scripting

Fgrep or grep or awk help - scanning for delimiters.

Hi, I'm struggling a little here, so I figured it's time to ask for help. I have a file with a list of several hundred IDs (the hit file- "hitfile.txt"), which is newline delimited, and a much bigger (~500Mb) text file, "FASTA.txt" with several thousand entries, delimited by ">". It's the... (8 Replies)
Discussion started by: Tbox
8 Replies

9. UNIX Desktop Questions & Answers

Difference grep, egrep and fgrep

Hi All, Can anyone please explain me the difference between grep, egrep and fgrep with examples. I am new to unix environment.. Your help is highly appreciated. Regards, ravi (2 Replies)
Discussion started by: ravind27
2 Replies

10. UNIX for Dummies Questions & Answers

I need help with fgrep or grep

How can I do an and condition with fgrep. I want to do: ps -ef | fgrep -f searchvalues > tempmail.file mailx -s "Email Subject" email@domain.com < tempmail.file The search values file contains: opt/bea.*java.*80 mysqld What I want is to find things that contain: mysqld OR... (7 Replies)
Discussion started by: jimmy
7 Replies
Login or Register to Ask a Question