solaris sed equivalent

Hi Experts,

I am using this command to edit the file contents and also add the header to the existing file.

I prepared this command on my VM (Linux) and it worked as I wanted it to work. But on solaris its not working :(. Please help as it is quite urgent.

sample File:

a
b

Output File:

H,0001
a,1,2
b,1,2

Command :

sed -e "i\H,0001" -e "s/$/,1,2/" abc > abc.tmp

I searched the forum and the man pages.. but unable to find out the desired results.

Many Thanks.

Try:

  1. Use ordinary quotes instead of double ones.
  2. Insert a literal newline after "i" command.
sed -e 'i\
H,0001' -e 's/$/,1,2/' abc > abc.tmp
1 Like

I don't know if solaris has an exact equivalent, but it's simple enough to rewrite that command in plain awk without nonstandard extensions. There's nothing in there that really needs sed, extended or otherwise.

awk 'BEGIN { print "H,0001" } { print $0 ",1,2" }' input > output
1 Like

AFAIK the i command in sed without the escaped newline is GNU sed only

Many thanks for all your replies. awk is also working. But for a big file of around 1 Million records, awk will be faster than sed ?

That depends on your implementations of awk and sed. Which is faster varies a lot from system to system.