Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print out lines with a crtain number at a certain position 3

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like search my log files for certain variables that occur in the same location on each line....

Once the variable (numer) is found then print the line out
 
The following will echo the characters that occur between position 10 and 15 of each line of the file logfile.log :
Code:
cat logfile.log | while read LINE
do
    echo $LINE | cut -c 10-15
done
You just need to put a conditional statement in there to catch the specific value or variable you're looking for.

--
-- Ghodmode
 
Why not simply this ?
cut -c 10-15 logfile.log

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
heheh ... well ya... if you want to do things the easy way ... [ponder] ...
but there's still something missing because jdespres didn't provide us with enough information. He needs a loop anyway. He doesn't want every line printed out, as in my solution, just the one that contains the value he's looking for.

PHVs way is still better, though :
Code:
NUMBER=[i]<some number I'm looking for>[/i]
cut -c 10-15 logfile.log | while read VALUE
do
    if [ $VALUE -eq $NUMBER ]
    then
        echo $VALUE
    fi
done

--
-- Ghodmode
 
The lines I want to print out will have either a 8 or a 16 in the 4th column... Space delimited....

Here's what I have so far: {I took Ghodmode's info}

#!/bin/ksh

# Scan through db error logs

NUMBER=$1
cut -d' ' -f4 $2 | while read VALUE
do
if [ $VALUE -eq $NUMBER ]
then
echo $VALUE
fi
done

And I get the following output:

$ ./check_errors.sh 16 /nbu2/openv/netbackup/db/error/log_1144123200
16
16
16
16
16
16
16
16
16
16
16
16
16
16
16

Still isn't there.... Atleast I'm firther ahead!

Thanks for the help!
 
#!/bin/ksh
awk '$4=='$1 $2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
perl -ane 'print if $F[3] =~ /^(16|8)$/'
will also work.


Rod Knowlton

IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

 
Hey PHV.... your last one worked!
.
Can you make a one liner out of it?

Thanks again!
 
Can you make a one liner out of it?
???
It's already a one liner !

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top