1834312 Members
2045 Online
110066 Solutions
New Discussion

grep functionality

 
SOLVED
Go to solution
Dave Walley
Frequent Advisor

grep functionality

Hi.

I have to extract from a file a string that contain slashes. I want to select a particular string from a file, the problem is that there are other lines that contain this string also.

The file contains the following lines among others. I only want to select the first i.e. not the line containing account.

/bkup/export
/bkup/export/account

I have tried using grep but with no sucess.

Can anyone please help me.

Dave


why do i do this to myself
5 REPLIES 5
Patrick Wessel
Honored Contributor

Re: grep functionality

try grep -x

good luck
There is no good troubleshooting with bad data
mark alexander
Occasional Advisor

Re: grep functionality

Dave,

Use the 'head' command to strip just the first line returned from grep, e.g.

grep '/bkup/export' filename | head -1

mwa
Dave Wherry
Esteemed Contributor
Solution

Re: grep functionality

This should work:
grep "/bkup/export" | grep -v "/bkup/export/"

Klaus  Frank
Frequent Advisor

Re: grep functionality

Hallo Dave

Why don't you try this

cat file_name | awk ? $1=="/bkup/export" ?

I allways prefare awk for it is much more powerfull than grep is.

best regards
Klaus
... we all can make it with a little help ...
Carlos Fernandez Riera
Honored Contributor

Re: grep functionality

Try :

grep '/bkup/export$' if lines ends w/ export

or grep '/bkup/export ' if not
unsupported