Hi,
I am trying to write a script which parses the fields in the program and prints them to standard output.
Input file data is like this
field1 field2
Fields are separated by tabs
Initially, I tried to write it in AWK.
cat test.txt | while read line; do entity=`awk -F "\t" '{print $2}'`;echo $entity; done
This works fine on command line.
But when I try to do the same in a shell program as below
while read line
do
entity=`echo $line|awk -F \t '{print $2}'`
echo $entity
done<"test.txt"
Reason being echo $line actually prints tabs as spaces. I cannot uses spaces because fields can actually contain spaces.
Then I tried to write using cut.
while read line
do
entity=`echo $line|cut -f5`
echo $entity
done<"test.txt"
Again same problem with echo.
Have anyone faced similar issue. Any solution that you can recommend me.
Thanks. Bala