Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IFS '\n' not working in AIX box

Tags:

shell

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

label.txt

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
like image 887
Vignesh Avatar asked Dec 07 '25 03:12

Vignesh


1 Answers

Try:

IFS='
'

(Just a carriage return there, no extra whitespace.)

like image 132
Mat Avatar answered Dec 08 '25 21:12

Mat