sed works on Linux and Unix does not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed works on Linux and Unix does not work
# 1  
Old 08-16-2011
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
# 2  
Old 08-16-2011
Maybe you need to esacpe it with \, like this \/ and try.
# 3  
Old 08-16-2011
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
# 4  
Old 08-16-2011
Try double quotes around that entire string.
# 5  
Old 08-16-2011
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.

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

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

Regards,
Alister

Last edited by alister; 08-16-2011 at 11:08 PM..
# 6  
Old 08-16-2011
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
# 7  
Old 08-16-2011
Quote:
Originally Posted by dude2cool
Try double quotes around that entire string.
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 ----------

Quote:
Originally Posted by andreirp
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
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed works on Linux but fails on Solaris

Hi, On Linux i get the desired ouput: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: Executing the same command on Solaris: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: I need to get the desired output on Solaris i.e. WEB_USER and... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Why statement works in LINUX and not UNIX?

Hello, I have a ksh script that uses code below. For some reason it works under linux but fails in unix. Any idea why? if ]; then ... Thanks (9 Replies)
Discussion started by: rdogadin
9 Replies

3. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfile This code... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

4. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfileThis code works well in... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

5. Shell Programming and Scripting

Delete rest of line with sed works on Linux but not on Solaris

Hi all, Our application installation uses "sed" command to delete rest of line. It work perfect on Linux but fail on Solaris. The OS versions are Solaris 9 and Linux Red Hat AS 3. yourfile.txt hello and world cat and dog hello world in linux: cat yourfile.txt | sed s/\(\+\)... (3 Replies)
Discussion started by: javac2005
3 Replies

6. Shell Programming and Scripting

Issue with script in linux but in unix works

I have this simple script: #! /usr/bin/sh #***************************************************************************** # *** get_input (question variable) *** #***************************************************************************** get_input () { echo "${BOLD}${1} : " read... (14 Replies)
Discussion started by: C|KiLLeR|S
14 Replies

7. UNIX for Dummies Questions & Answers

Remote Unix printing to my WinXP works with no router. How can I make it work through my router?

I set up remote printing on a clients Unix server to my Windows XP USB printer. My USB printer is connected directly to my PC (no print server and no network input on printer). With my Win XP PC connected to my cable modem (without the router), i can do lp -dhp842c /etc/hosts and it prints. I... (7 Replies)
Discussion started by: jmhohne
7 Replies

8. UNIX for Dummies Questions & Answers

what's the Linux|Unix OSes works on Servers

Hi everybody , I'm new here in the forum and new Dummy in L|U systems (Hope finding welcomes...:)). I just want to ask : What is the OS's that works on servers and the OS's that work as client OS?? I just know that Solaris Work on sarvers :D.. and i'm glad to be memmber in this... (1 Reply)
Discussion started by: derbi
1 Replies

9. UNIX for Dummies Questions & Answers

Any Linux/Unix work with SATA yet?

i got my computer in 2k, built it myself. top of the line then and better than most still now. one problem however is i was never able to install unix because the old kernels were not compatible with SATA hard drives i dont have any IDE drives nor do i want any I want mine on SATA, but every... (5 Replies)
Discussion started by: GXDeMoNN
5 Replies

10. Shell Programming and Scripting

Appending line with sed works on Linux but not on Solaris

Hi folks, Our application installation uses "sed" command to append string after specific line or after line number. Both cases work perfect on Linux but fail on Solaris. The OS versions are Solaris 9 and Linux Red Hat AS 3. i.g: Linux: ----- file foo.txt aaa bbb ccc ddd root#... (4 Replies)
Discussion started by: nir_s
4 Replies
Login or Register to Ask a Question