Hi,
I'm trying to read a file containing lines with spaces in them.
The inputfile looks like this
------------------------------
Command1 arg1 arg2
Command2 arg5 arg6 arg7
-------------------------------
The shell code looks like this...
lines=`awk '{ print }' inputfile`
for LINE in $lines ; do
echo ${LINE}
done
output is
--------------------
Command1
arg1
arg2
Command2
arg5
arg6
arg7
--------------------
What I really want is
--------------------
Command1 arg1 arg2
Command2 arg5 arg6 arg7
How do I do it..
TIA.
In most shells, the usual way to get an entire file into a variable is:
file=$( cat "$FILE" )
In bash (and ksh93) you can save a process with:
file=$( < "$FILE" )
But the usual way to read a file line by line in the shell is:
n=0
while IFS= read -r line
do
printf "%3d: %s\n" "$(( n += 1 ))" "$line"
done < inputfile
IFS=$'\n'; for line in $lines; do