3

I need to get the output file same as the input file format after passing through the while loop.

eg:

cat samp.csv

a     b           c              d
cat samp.csv | while IFS= read -r line
do
echo $line
done

after passing samp.csv in while output :

 
a b c d

expected output :

a     b           c              d 

Could anyone please suggest me?

2

1 Answer 1

4

In bash, the string separated by spaces is split into words (word splitting). So four arguments are given to echo. If you want your blank spaces you need to add quotes to the variable $line, so only one argument is passed to echo.

cat samp.csv | while IFS= read -r line
do
echo "$line"
done

Output:

a     b           c              d 
2

Not the answer you're looking for? Browse other questions tagged .