This question already has an answer here:

I'm using IBM AIX which doesn't have much support like sed -i and sed with \t is not working in my case.

I would like to replace replace NotApplicable string with a single space ' ' then replace @@@ multi-char-delimiter with a tab delimiter, in a specified order using single command be it awk, or sed.

I tried using sed as following but it didn't work. Couldn't add search and replace for NotApplicable with a ' ' single space in below command.

sed 's/@@@/\t/g' file.csv > file.xls

Sample data.


cola    colb    colbc
test    test    test
test            test
123     145     567
333     444         

marked as duplicate by Jeff Schaller, JigglyNaga, Archemar, X Tian, elbarna Nov 28 '18 at 14:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • If you're just doing this from the command line (not writing a script which should pass code review ;-)) you can simply enter the tab manually with Ctrl-v Tab. (your command will look like sed s/@@@/ /g ...) – mosvy Nov 28 '18 at 3:32

Translating Gilles' answer to this situation, it'd be:

sed $'s/@@@/\t/g; s/NotApplicable/ /g' file.csv > file.xls

This uses ANSI-C quoting to allow interpretation of \t as a TAB; everything else inside the quotes is the existing sed command.

  • I like to replace NotApplicable to single space ' ' as well using same sed. – mr_eclair Nov 28 '18 at 1:59
  • see edited Answer – Jeff Schaller Nov 28 '18 at 2:00
  • Didn't work in my case. – mr_eclair Nov 28 '18 at 2:04
  • 1
    What does "didn't work" mean? The changes don't happen? You get an error? – Jeff Schaller Nov 28 '18 at 2:07
  • 2
    @JeffSchaller I don't think that the ksh88 (?) on AIX has support for $'...'. – mosvy Nov 28 '18 at 9:30

There are probably more obvious ways to do it, but one way to generate any character on any unix system is with tr(1):

tab=`echo t | tr t '\011'`
sed "s/NotApplicable/ /g; s/@@@/$tab/g" file.csv > file.xls

Notice the double quotes around the sed command.

Not the answer you're looking for? Browse other questions tagged or ask your own question.