Hey guys, I am trying to make sed append every line containing a string with another line. problem is the appended line needs to start with a tab: # sed -i '/string/a \tstuff\t\t\tmorestuff' file Obviously \t or \x09 etc doesn't get interpreted unless there are other characters before it? How can I get this to begin with a <tab>?
Thanks! jlc
Hi,
On Wed, Aug 19, 2009 at 13:24, Joseph L. CasaleJCasale@activenetwerx.com wrote:
Hey guys, I am trying to make sed append every line containing a string with another line. problem is the appended line needs to start with a tab: # sed -i '/string/a \tstuff\t\t\tmorestuff' file Obviously \t or \x09 etc doesn't get interpreted unless there are other characters before it? How can I get this to begin with a <tab>?
Hi,
The "a" command expects to be followed by a "", so it's eating the one in your first "\t". If you add another "" it seems to work as you want it to:
$ echo string | sed '/string/a \tstuff\t\t\tmorestuff' string stuff morestuff $
HTH, Filipe
The "a" command expects to be followed by a "", so it's eating the one in your first "\t". If you add another "" it seems to work as you want it to:
$ echo string | sed '/string/a \tstuff\t\t\tmorestuff' string stuff morestuff $
Ah ffs, lol... It would also help if I emailed what I was typing. I use so many versions, I get mixed up. I typed the email with <'> but wrote <"> in the console which is why I couldn't make it work.
'/string/a \tstuff\t\t\tmorestuff' != "/string/a \tstuff\t\t\tmorestuff"
Thanks Filipe! jlc
Hi,
On Wed, Aug 19, 2009 at 16:20, Joseph L. CasaleJCasale@activenetwerx.com wrote:
'/string/a \tstuff\t\t\tmorestuff' != "/string/a \tstuff\t\t\tmorestuff"
Yes, indeed... The rules of quoting and backslashes in the shell are not very uniform and can get quite tricky... Also, the \t is interpreted by sed, and AFAIK it is available in GNU sed only, so the syntax you are using above might not be very portable to other versions of "sed". If your script gets this tricky it's probably time to move to Perl, which can also do that easily in an one-liner and, in this case, might actually be more portable. (Heck, it might even be more readable!)
HTH, Filipe