get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS ,
i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one.

thanks...

Venu

This will get you the 5th line

sed -n 5p infile

To check for "string" in 5th line:

awk 'NR==5&&/string/ {exit 1}' infile || echo "Found it!"
1 Like

@chubler.....the text file is replaced with new contents every day and i want to check the found word with the 6 type of words i have and if the word is matched with the word , then i want to send it into a variable....

word=$( awk 'NR==5 { for(i=1;i<NF;i++)
    if ($i ~ /string1|string2|string3|string4|string5|string6/)
        { print $i; exit }
    }' infile )

Word will be blank or first of your 6 strings found on the 5th line