I am trying to read a file which has several lines and print it as it is. But my new line in IFS is not working as expected. This is in AIX.
Below is my script,
#!/bin/ksh
#set -x
old_IFS=$IFS # save the field separator
IFS=$'\n'
LABELFILE=/home/david/label.txt
OUTPUT_FILE=/home/david/label_out.txt
for i in $(cat $LABELFILE)
do
echo "$i" >> $OUTPUT_FILE
done
Hello nancy
naghu naghu
Hello navy
You are naughty
Good niece
My Output file(label_out.txt->
Hello
a
cy
aghu
aghu
Hello
avy
You are
aughty
Good
iece
Expected output->
Hello nancy
naghu naghu
Hello navy
You are naughty
Good niece
Try:
IFS='
'
(Just a carriage return there, no extra whitespace.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With