Hi all;
I am trying to read a file in to test if the string "User" is present if so I would like to place a '#' infront of "User". The script I have below seems to do the job, except the spaces/indents of the original file go missing.
Here is an example of the file I am reading:
And here is the copy of the final output:
As you can see the "neat" indents have dissappeared, any ideas on how to prevent this?
Any and all help is greatly appreciated!
Sean.
I am trying to read a file in to test if the string "User" is present if so I would like to place a '#' infront of "User". The script I have below seems to do the job, except the spaces/indents of the original file go missing.
Here is an example of the file I am reading:
Code:
/tmp/sally.txt
Hello there Sally
When is it going to happen
User
Today perhaps?
User
[code]
Here is the code I use to change the file:
[code]
#!/bin/sh
infile="/tmp/sally.txt"
while read line ; do
t=${line/User/\#User}
echo ${line} >> /tmp/other.txt
done < $infile
mv /tmp/other.txt /tmp/sally.txt
Code:
/tmp/sally.txt
Hello there Sally
When is it going to happen
#User
Today perhaps?
#User
As you can see the "neat" indents have dissappeared, any ideas on how to prevent this?
Any and all help is greatly appreciated!
Sean.