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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop 2

Status
Not open for further replies.

SpongeBob1

Programmer
Mar 1, 2002
49
0
0
US
hi,

Is there any way in unix ( ksh ) to do pattern matching? eg. in my script I want to pick out the ID's from a log file so I'm thinking something like....

searching for id=*, pick this from my log file & print it...
any ideas?

Thanks.
D.
 
SpongeBob:

Sure, Unix can do this for you using regular expressions. This little awk script first checks if the line has id=* in it and then searches each field for id=*:

#!/bin/ksh

nawk '
{
if($0 ~ /id=*/)
{
for (i=1; i<=NF; i++)
{
if($i ~ /id=*/)
print $i
}
}
} ' log.file

I couldn't interpret what you wanted printed, so this example just prints id=*. It might be more efficient to remove the global $0 line search.

Regards,


Ed
 
put in a file called what-you-want

---------------------start here
#n
/1-id-to-print/p
.....
/N-id-to-print/p
--------------------stop here

then execute 'sed'

sed -f what-you-want log-file-name
you also can say:

cat log-file-name | sed -f what-you-want
 
you can do this entirely with ksh.
I need more info.
give me a matching line.

Regards gregor.
Gregor.Weertman@mailcity.com
 
Mike:

You get the star for the &quot;interesting reading&quot; URL.

Thanks!

Ed
 
I second that - nice link.

mucho thanks vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
IFS=&quot; &quot;
ll |while read x
do
set -k -- $x
if [ &quot;$3&quot; = &quot;root&quot; ] ;then
echo $2 $3 $5
fi
done

This is fun indeed.
regards Gregor. Gregor.Weertman@mailcity.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top