How to cut the particular string and increment the rows?

Hi am using unix aix

I have tried using awk but am getting only output = x ,its not incrementing next output
 
set -A var1 vv qa za
ct=0
i=3
while [ $ct -lt 3 ]
do
var1=`echo ${var1[$ct]}`
count=`awk ' NR==$i++ {print;exit}' ${.txt} | cut -c5 `
echo $count
let ct=ct+1
done

Can anyone help me how to increment NR

Hi,

Try this one,


awk '{print "Count="substr($0,6,1);}'  input_file

perl -lne 'print "Count=",substr($_,5,1);' input_file

Cheers,
Ranga :slight_smile:

HI Its not working

echo "|28|
vv |xcvb|
qa |cerd|
za |qwer|" | awk '/^[a-z]/ {print "output="substr($0,5,1);}'
output=x
output=c
output=q

Try:

awk -F"|" '$1!=""{print "output = ", substr($2,1,1)}' .txt
output =  x
output =  c
output =  q

AND - please use proper code tags!

Try like...

 awk -F"|" '{print "output="substr($2,1,1)}' test.txt 

This gives errada output

output=2
output=x
output=c
output=q