How to append text to the second line of a file
Say I have a text file like:
Code:
1 Edit: Okay it's not bash, it's ksh because this computer is OpenBSD |
This should work:
Code:
sed '1a\2' infile |
Hey,
I get the error: Code:
$ sed '1a\2' infile |
Is it the EXACT output of your command?
|
What do you mean? What you see is the exact same thing I get
Code:
$ sed '1a\2' infile |
That's weird. It works for me:
Code:
sycamorex@mainframe:~/temp$ less file.txt |
sycamorex's idea also works fine for me. Maybe a version difference? I have:
Code:
root@reactor: sed --version Code:
root@reactor: cat file.txt |
Can you try:
Code:
sed '1a2' infile |
Ah, well...
Is there some sort of alternative to sed? |
Quote:
Code:
$ sed '1a2' file.txt |
Quote:
Code:
$ sed --version |
Yeah, what distro and sed version are you using?
1a2 works for me as well. Edit: I use the same version as GrapefruiTgirl does. |
I have seen this before, on weird versions of sed, like on Solaris and other non-Linux machines. They don't like to show what version they are or anything :/
It may help to know more about the larger project, in order to suggest a workaround that will work in all cases. Surely you don't have 1000 files that need a "2" added into them, so maybe there's a way to get the "big picture" accomplished, if we can understand what the whole project entails? Plus - maybe sed can still be used, but instead of using the insert/append functionality, we'll just match a regex and add some stuff, like: Code:
root@reactor: cat file.txt |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 09:44 AM. |