grep only a string on command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep only a string on command output
# 1  
Old 06-25-2010
grep only a string on command output

How can I grep exactly a string that has .,/ characters using grep?

Example: I want to grep ONLY string1 and not string1.more or string1.more.evenmore

#lsauth ALL|grep 'string1'

All output:
string1 <--- This is the only I want.
string1.more
string1.evenmore.
more.string1
evenmore.string1.more

thanks in advance.
regards
Israel.
# 2  
Old 06-25-2010
Code:
lsauth ALL | egrep '^string1$'

# 3  
Old 06-25-2010
Hi bartus11
umm.. doesn't work for me...:-(

I'm testing on AIX 6.1. When I run the command it does not return any output.

regards,
Israel.
# 4  
Old 06-25-2010
Hi

Code:
#lsauth ALL|grep 'string1[^.]'

Guru.
# 5  
Old 06-25-2010
Maybe there is space after or before "string1"? Try
Code:
lsauth ALL | egrep '^string1 $'

or
Code:
lsauth ALL | egrep '^ string1$'

Anyway real output generated by "lsauth" would be much more helpful.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Single grep to multiple strings with separate output per string

I need to grep multiple strings from a particular file. I found the use of egrep "String1|String2|String3" file.txt | wc-l Now what I'm really after is that I need to separate word count per each string found. I am trying to keep it to use the grep only 1 time. Can you guys help ? ... (9 Replies)
Discussion started by: nms
9 Replies

2. Shell Programming and Scripting

Grep for string and then output...

Hi all, I have a file: /var/log/lct/buildinformation I am trying to grep for string: MANUFACTURER : VMware, Inc. If it contains the string I want to output the results of:df -h |grep '/usr|/var' |awk '{print $6 " "$5}' If it does not have the above string to send a no vm found... (6 Replies)
Discussion started by: gartie
6 Replies

3. Shell Programming and Scripting

Grep output to awk command

Hi Team(Solaris 5.8/Ksh), How can we save grep output to awk variable when grep returns more than one line or word. abc.log # more abc.log Hi Makarand How r u bye Makarand Hello when grep returns only 1 word below command works nawk -v var=`cat abc.log |grep "Hello"` 'BEGIN { if... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

4. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

5. Shell Programming and Scripting

Want to terminate command execution when string found in the command output

Hi Experts, I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task. I am running below command to snmpwalk the router.. snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
Discussion started by: Hanumant.madane
19 Replies

6. UNIX and Linux Applications

How to redirect grep command output to same file

Hi Everyone, Can anyone please tell me, how can I redirect the grep command output to same file. I am trying with below command but my original file contains no data after executing the command. $grep pattern file1 > file1 Kind Regards, Eswar (5 Replies)
Discussion started by: picheswa
5 Replies

7. UNIX for Dummies Questions & Answers

Using grep output as input for sed command

Hi, I would like to know if this is possible, and if so what can i do to make this work. I would like to grep a line X from fileA and then use the output to replace a word Y in fileB. grep "line X" fileA | sed -e 's/Y/X/g' > outfile this statement does not work, as i do not know how to... (7 Replies)
Discussion started by: cavanac2
7 Replies

8. Shell Programming and Scripting

Remove a specific line from grep output string

Dear All I want to search string "1000" from input file and if it found i want remove line that contain 1000 and also remove 3 line above it and 2 line below it. INPUT FILE: BHAT-D 2 aaa ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES 50 ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

9. Shell Programming and Scripting

grep string and output filename

Hello, I have over 200 files and some of them have the string like "John price $200". I would like to grep the string. Then output the filename which found the string. I have the following script, but it ONLY output the string echo Please input list file name: read listn for file in `cat... (3 Replies)
Discussion started by: happyv
3 Replies

10. UNIX for Dummies Questions & Answers

piping the output of find command to grep

Hi, I did not understand why the following did not work out as I expected: find . -name "pqp.txt" | grep -v "Permission" I thought I would be able to catch whichever paths containing my pqp.txt file without receiving the display of messages such as "find: cannot access... Permisson... (1 Reply)
Discussion started by: 435 Gavea
1 Replies
Login or Register to Ask a Question