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

awk question

Status
Not open for further replies.

vaat

MIS
May 14, 2002
27
NL
how do I display the fiels after the awk field search ?

so je search for a string like:

nawk '/string/ {print $1}' filename

it is printing colomn 1 but I want the colomn after the string, that can be colomn 1,2,4,6,100 en so on !

alex
 
This sounds something like:

/string/ {
for( i = 1; i <= NF; i++ )
if( $i ~ /string/ ) print $(i+1)
}

Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
this works: thanxs all


for i in `ls startrek*`
do
echo $i
sp=`nawk '!/--/ && !/stardate/ {print $0}' $i`;
cr=`nawk -F, '/--/ {print $1, $2}' $i`;
st=`nawk -F &quot;stardate&quot; '/stardate/ {print $2}' $i`;
echo $st @ $cr @ $sp >> bla
done

sort -fi bla | nawk -F@ '{printf &quot;STARDATE\t %s\n CREDITS\t %s\n SPREUK\t\t %s\n\n&quot;, $1, $2, $3}' > uitvoer
rm bla


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top