tags:

views:

19

answers:

2

hi dear friends

need advice about the following

with the following ksh script I actually copy file1 to file2 my problem is that lines in file2 are not with the same location as file1

 #!/bin/ksh

 while read -r line ; do 
 echo $line >> file2
 done < file1

for example

more file1
  line1
      line2
         line3


more  file2
line1
line2
line3

the question what I need to change in my script in order to get lines location as described in file1? after I run my ksh script?

lidia

A: 

You can try:

while read -r line ; do 
echo $line | sed -re 's/^\s+//' >> file2
done < file1

This uses sed to get rid of the leading whitespaces present in lines from file1.

codaddict
its not work the lines are not the same
lidia
A: 

you can set IFS=

while IFS= read -r line ; do echo "$line"; done<file
ghostdog74

related questions