inserting text into a file
Howdy,
This is what I am looking at sed /$expression/a\ "$comment" $fname > $fname.cmt no problem with it except that i want to edit the file $fname itself the problem is $fname is being written with cat /dev/ttyUSB0 >> $fname I would like to be able to actually insert the comment into $fname without causing a problem with the file as it is being written. sed /$expression/a\ "$comment" $fname > $fname results in an empty file may I need to use echo or something thanks, |
Re: inserting text into a file
I think I have doen something similar before and I had to use echo - eg:
echo `sed /$expression/a\ "$comment" $fname` > $fname |
It seems to work, except that the line is inserted without a new line at the end
~090 File Number:9030, Shot Number:2977, Shot Point Line:562 , Station:123 Observers comment: Hello ~090 Mag Tape Usage: MT2U0-raw I have not checked to see what is happening to the cat process yet. |
What am I thinking - when I was doing something similar it was with a different script (perl search and replace type script). With sed you can just use the -i switch.
sed -i /$expression/a\ "$comment" $fname |
that's it
hard to believe it was that simple learning sed is fun :) |
Yeah - the funy thing was the first time I really used it was for modifying shadow password files - just as well I made backups first :D
|
All times are GMT -5. The time now is 08:25 PM. |