I am looking to extract 2 names from a pipe delimited file which looks like below,
1|1234|first name|2|56768|second name |message
my code looks like below,
cat $file_name|while read row; do
name1=`echo $row | awk -F\| '{ print $3 }'`
name2=`echo $row | awk -F\| '{ print $6 }'`
echo name1 is $name1
echo name2 is $name2
The problem I am facing is above code is removing multiple spaces within the actual data and also removing trailing spaces.
I need to have data as it is e.g. it should keep multiple spaces within data if original data has multiple spaces within it.
can anyone please suggest how can I extract name1 and name2 as above preserving spaces in the data ?
if reading fields by while loop or by awk is not good method then can you please suggest alternative way or perl script way instead of bash ??