Computing.Net > Forums > Unix > Only grep a particular string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Only grep a particular string

Reply to Message Icon

Name: Junes
Date: July 6, 2006 at 09:30:05 Pacific
OS: unix
CPU/Ram: na
Product: na
Comment:

I want to grep a file that will only output the content of the file which meet the following conndition:

File Content
=============
emalon
emalonv1
emalonv2

If i want "emalon" to be grepped and outputted and not "emalonv1" and "eamlonv2", what will be the syntax.

King Regards

Junes



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 6, 2006 at 10:05:24 Pacific
Reply:

Sine your file only has 3 lines, this regular expression works:

grep 'emalon$' data.file

The above works because it searches for emalon at the end of a line.

If your grep supports the word option, -w, this works:

grep -w 'emalon' data.file


0

Response Number 2
Name: Junes
Date: July 7, 2006 at 07:32:34 Pacific
Reply:

More advice please

I can't get the following expression to provide the correct output.

LastFDrive=`cat $LASTFAILEDDRIVE_Drive | awk '{print $1}' | grep -w $DriveName`

+ + cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive
+ grep -w Dr305
+ awk {print $1}
LastFDrive=
+ + grep -w emalonvme00v1
+ cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive
+ awk {print $2}
LastFServer=

If i run via CLI, it works

cat $LASTFAILEDDRIVE_Drive | awk '{print $1}' | grep -w $DriveName

Can someone provide some advice

King Regards

Junes


0

Response Number 3
Name: ghostdog
Date: July 10, 2006 at 01:37:35 Pacific
Reply:

how come its "awk {print $2}" instead of
"awk {print $1}" , is it typo error?


0

Response Number 4
Name: Junes
Date: July 10, 2006 at 03:25:29 Pacific
Reply:

Its not a typo, file cat $LASTFAILEDDRIVE_Drive contains the following

File Content
=============
Dr306 emalon
Dr309 emalonv1
Dr301 emalonv2

Any adivce please for the following question!!!!!


----------

More advice please
I can't get the following expression to provide the correct output.

LastFDrive=`cat $LASTFAILEDDRIVE_Drive | awk '{print $1}' | grep -w $DriveName`

+ + cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive
+ grep -w Dr305
+ awk {print $1}
LastFDrive=
+ + grep -w emalonvme00v1
+ cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive
+ awk {print $2}
LastFServer=

If i run via CLI, it works

cat $LASTFAILEDDRIVE_Drive | awk '{print $1}' | grep -w $DriveName

King Regards

Junes


0

Response Number 5
Name: ghostdog
Date: July 10, 2006 at 06:20:47 Pacific
Reply:

by right it should work. What is the correct output?


0

Related Posts

See More



Response Number 6
Name: Junes
Date: July 10, 2006 at 07:16:57 Pacific
Reply:

# cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive
>> - Dr306 emalon
# cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive | awk '{print $1}' | grep -w Dr306

>> - Dr306

# cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive | awk '{print $2}' | grep -w emalon

>> - emalon

But when i run the command via the script, i do not get the output that i require.

LastFDrive=`cat $LASTFAILEDDRIVE_Drive | awk '{print $1}' | grep -w $DriveName`

+ + cat /usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive
+ grep -w Dr305
+ awk {print $1}
LastFDrive=
+ + grep -w emalonvme00v1


The following syntax is incorrect,


LastFDrive=`cat $LASTFAILEDDRIVE_Drive | awk '{print $1}' | grep -w $DriveName`

I need advice.!!!!!


King Regards

Junes


0

Response Number 7
Name: ghostdog
Date: July 10, 2006 at 09:23:35 Pacific
Reply:

can you show the whole script, without those extra debugging info.


0

Response Number 8
Name: Junes
Date: July 11, 2006 at 01:13:54 Pacific
Reply:

#! /bin/ksh

touch /tmp/drive_status
touch /tmp/drivetest.txt
BPSTORAGEUNIT=/usr/openv/netbackup/bin/admincmd
DRIVESTATUS=/usr/openv/volmgr/bin
LASTFAILEDDRIVE_Drive=/usr/openv/netbackup/BOA_scripts/temp_files/lastfaileddrive

for SERVER in `$BPSTORAGEUNIT/bpstulist | awk '{print $3}' | sort -u`
do
echo "SERVER NAME IS:=> $SERVER"
$DRIVESTATUS/vmoprcmd -h $SERVER | grep -i DOWN | awk '{print $1,$3}' |
while read LINE
do
IGNORE=NO
DriveIndex=`echo $LINE | cut -f1 -d" "`
DriveStatus=`echo $LINE | cut -f2 -d" "`
DriveName=""
DriveName=`$DRIVESTATUS/vmoprcmd -h $SERVER -d ad | awk '$1=='$DriveIndex' {print $2}'`
if [ $DriveStatus = "DOWN" ] || [ $DriveStatus = "DOWN-ACS" ] || [ $DriveStatus = "DOWN-AVR"
];then
# Check to see Failure Notification has not already been submmitted
LastFDrive=`cat $LASTFAILEDDRIVE_Drive | awk '{print $1}' | grep -w $DriveName`
LastFServer=`cat $LASTFAILEDDRIVE_Drive | awk '{print $2}' | grep -w $SERVER`
if [ $LastFDrive != "" ] && [ $LastFServer != "" ]
then
continue;
else


King Regards

Junes


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Only grep a particular string

grep - print next line too www.computing.net/answers/unix/grep-print-next-line-too/7417.html

Script to scan files for a string www.computing.net/answers/unix/script-to-scan-files-for-a-string/7532.html

Extracting string using regular exp www.computing.net/answers/unix/extracting-string-using-regular-exp/5762.html