sed works on Linux and Unix does not work

Hi,

I use this command in Linux but if I run the same command does not work in freebsd.

Follow the below command:

Linux works:

sed -e '1731a\' -e '####' squid.conf > squid2.conf ; sed -e '1731a\' -e 'acl TESTE_ip src 192.168.1.1/255.255.255.255' squid2.conf > squid.conf ; sed -e '1731a\' -e '########' squid.conf > squid2.conf ; sed -e '1731a\' -e '#####' squid2.conf > squid.conf

Freebsd displays the following error:

sed: 1: "acl TESTE_ip src 192.16 ...": command a expects \ followed by text

Could someone help me ?

Tks

Maybe you need to esacpe it with \, like this \/ and try.

thank you for reply.

I already tried to escape with \ the 'a' command the '\/'.

In this message, something to do with the command a(append) that I put together with the line.

sed: 1: "acl TESTE_ip src 192.16 ...": command a expects \ followed by text.

On Linux it works perfect but does not work in freebsd.

---------- Post updated at 07:30 PM ---------- Previous update was at 07:21 PM ----------

The a is not the line but the 'acl ...., i try escape '\acl but now other error display.

"\acl TESTE_ip src 192.1 ...": unterminated regular expression

Try double quotes around that entire string.

It would really help if you would clearly state what it is that you are trying to accomplish.

In any case, a guess: With regard to POSIX, GNU/Linux sed is a mess. GNU goes beyond compatible extensions and happily disregards basic command behavior (most notably, the N command). If you are trying to append text, use a newline after the backslash after the a command.

sed '1731a\
####' squid.conf'

If you are not attempting to add a line of "####" after the 1731st line, then please explain further.

Regards,
Alister

Thanks for the reply.

Exactly, but I would like to add multiple lines and this command line would I assign a variable as:

$exec = "sed '1731a\ ####' squid.conf'"

How will I assign a variable with line break?

The output in a text file "squid.conf" would be:

#####
acl TESTE_ip src 192.168.1.1/255.255.255.255
########

tksss

Absolutely no point. Anything that could possibly be special to the shell is already protected by strong quotes (single quotes).

Regards,
Alister

---------- Post updated at 09:22 PM ---------- Previous update was at 09:17 PM ----------

That command line will most likely just throw an error. You can't have whitespace around the "=" in an assignment.

Why don't you do yourself and us a favor and walk us through what it is that you are trying to accomplish. Step by step. Assume nothing. Break it down. Give us a few lines of input and the expected output. If you are trying to assign or extract something into a variable, give us context.

Regards,
Alister

thankss

The command it works. tks

sed -e '1a\
######' -e '1a\
> acl TESTE_ip src 192.168.1.1/255.255.255.255' squid.conf

All in a line without newline, is it possible? I will assign to a variable as:

tkssss

---------- Post updated at 08:51 PM ---------- Previous update was at 08:45 PM ----------

Tkss Alister

I would like now execute the command below in one line, without newline. if I remove a newline does not work as:

sed -e '1a\ ######' -e '1a\ acl TESTE_ip src 192.168.1.1/255.255.255.255' squid.conf

Tkss Alister

---------- Post updated at 08:56 PM ---------- Previous update was at 08:51 PM ----------

I will first test in the shell, after work I'll run the command via php. I put the entire command in double quote to run.

Tksss