Required Command in awk command

Hi Firends,

I wanted to extract the first record of the file which starst with character say "X". And I tried an awk command which works when i try to execute it individually:

awk 'substr($1,1,1)=="X"' inputfile.txt

But when I use the same command in my script for which I am passing the parameters, it extracts the first record and the last record:

 awk 'substr($0,$1,$2)==$3' $File_Name >> /WorkingDirectory/Header_Trailor.txt

where $1 = Character Length
$2 = Character Position
$3 = Search String

Please help me on this regard. Suggessions will be helpful.

Thanks,
Ajay

If you are passing these parameters, then define awk variables and use them:

awk -v s="$1" -v l="$2" -v c="$3" 'substr($0,s,l)==c' "$File_Name"

Thanks a lot Yoda.. It worked.... :slight_smile: