Quote:
Originally Posted by
Nicole Hamilton
Hi, I'm the author of Hamilton C shell. The reason for the different behavior under Linux than under my C shell is that I followed the POSIX 1003.2 standard for sed and the other utilities. Linux doesn't, or at least, not always.
Under the POSIX standard, as someone else already pointed out, the text you'd like to add using sed should start on a new line and each embedded newline should be preceded by a backslash. You can do that in a variety of ways.
From the C shell command line, use the ^n escape sequence. (I'm assuming you're using the default Windows-style setting for the escape character.)
65 C% cat > DaysOfWeek
Monday
Tuesday
Wednesday
Thursday
Friday
^Z
66 C% sed '/Friday/a\^nSaturday\^nSunday' DaysOfWeek
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
67 C% _
From the command line, escaping the Enter key. (My C shell doesn't just embed newlines if you type Enter in the middle of a quoted string; you have to escape them.)
67 C% sed '/Friday/a\^
Saturday\^
Sunday' DaysOfWeek
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
70 C% _
In a script:
70 C% cat >AddWeekend
/Friday/a\
Saturday\
Sunday
^Z
71 C% sed -f AddWeekend DaysOfWeek
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
72 C% _
Hope this helps.
Thanks Nicole for your solution , Now i am able to insert / append using hamilton.
-----Post Update-----
HI Nicole,
Is it possible to use same syntax in csh script.
Now my problem is that i need to append a text file using sed. So i make following script, but in this case when i run it , it says that sed \ must terminate a command
#!/bin/csh -f
foreach file (`ls *.txt`)
sed "/Some_Text/a\^n NEW_TEXT" $file
end
Actually i tried the same syntax with proper file name in command prompt and it works there.
Can you please help me.
Thanks
Regards
Sarbjit
-----Post Update-----
Hi Nicole,
I tried the following and then i am able to use sed in csh script.
eg:
sed -f script file.txt
and in script i have written
/SOME TEXT/a\
NEW TEXT
and it works
Now my question is why i am not able to use
sed '/SOME TEXT/a\^n NEW TEXT' file.txt in csh script , but if i use same syntax in hamilton command prompt it works fine.
appreciated your help in advance
Regards
Sarbjit Singh