Hi,
I have a test.txt and would like to put in a different file but while putting in the other file, blank spaces are missing.
$ indicates blank spaces
filename: test.txt:
USA$$$840$$$$
Desired output
USA$$$840$$$$
Current output as per the following code.
while read j;
do
echo "${j}" >> out.txt
done < test.txt
Output:
out.txt
USA$$$840
Thx
kshji
February 16, 2010, 12:03pm
2
read use IFS values to parse line, space is part of IFS (input field separator).
So you need to change space => Ctrl-A (ascii 1), then read line
cat test.txt | tr " " "\001" | while read line
do
# convert back Ascii-1 to space
echo "$line" | tr "\001" " "
done >out.txt
Or using some other delimiter as "white space", ex. set ASCII 1 is input delimiter
while IFS="\001" read line
do
echo "$line"
done < test.txt > out2.txt
alister
February 16, 2010, 12:24pm
3
You can just set IFS to an empty string:
IFS=""
That will guarantee that no field splitting is done and that leading/trailing whitespace is not discarded in the process. Choosing some seldom seen character/byte as the value for IFS always incurs the risk that the splitting will occur on that value if it rears its head.
Regards,
alister
Gr8..thanks..this is working..)