|> I am writing a sh shell script and I need to read a file line-by-line into
|> a variable without changing the lines. I am using a While loop as shown below
|> but it is stripping off leading spaces and multiple spaces in the line it is
|> reading in! Does anyone know a way to read in a file line-byline without
|> modifying the line?
|> Script currently being used:
|> while read j
|> tc_title=$j # store the TC title line in variable tc_title
|> echo "$tc_title" >> $temp_dir/temp_9
|> done < $tc_files_dir/$i
|> Thanks for any help.
Try the following:
#--set counter for sed
VAR=`sed -n ''$i'p' $FILENAME`
if [ "$VAR" = "" ] #---break if line has no chars or EOF
#---do file processing here
#---quotes ensure that line echoes with initial spaces
#---don't forget to increment the counter
i=`expr $i + 1`
This will echo one line of FILENAME at a time, progressing top to bottom.
Hope this helps.