echo & sed problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo & sed problems
# 1  
Old 04-15-2011
echo & sed problems

I need a script to to instert the following line into my postfix master.cf file:
Code:
      flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}

if I use echo I get the line truncated:
Code:
:~ echo       flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}
flags=Rq user=filter argv=/etc/postfix/disclaimer -f --

I guess it's the $ characters, so I tried sed instead but get this error:
Code:
:~ sed 's/dfilt     unix    -       n       n       -       -       pipe.*/& \n        flags=Rq user=filter argv=/etc/postfix/disclaimer -f/' /etc/postfix/master.cf2 > /etc/postfix/temp_file
sed: -e expression #1, char 108: unknown option to `s'

either option would work as this just needs to added at the bottom of the file. Must be simpleSmilie

Thankyou
# 2  
Old 04-15-2011
Place the entire string between single quotes (').
# 3  
Old 04-16-2011
Thanks, works great for echo. Just for my own benefit, how do I make it work with sed (as this is generally more useful)?
Smilie
# 4  
Old 04-16-2011
you just need to escape the "/" in your new string using "\".
Code:
sed 's/dfilt     unix    -       n       n       -       -       pipe.*/&\n        flags=Rq user=filter argv=\/etc\/postfix\/disclaimer -f/' file > output

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Echo "abc" | sed - r 's/a/&_&/

I want to know the working of & here step by step using sed command. (1 Reply)
Discussion started by: Preeti07
1 Replies

2. Shell Programming and Scripting

Problems with ampersand (&) in sed command

Hello everybody, I have a Problem with sed command. I want to replace a defined string with a string from a database field (dynamic). e.g. sed -i -e 's/%NAME%/'"$HNAME"'/g' The Problem is that the $HNAME variable can contain Special characters like '&' e.g. HNAME="AH Kruger & Co. KG" ... (1 Reply)
Discussion started by: Bambuti2000
1 Replies

3. Shell Programming and Scripting

\n in ksh using echo & printf

#!/usr/bin/ksh var1="Hi World" var2="Morning" var3=$(echo "$var1" \n "$var2") echo $var3 var3=$(printf "$var1 \n $var2") echo $var3 Output Any way to get in my $var3 ? (7 Replies)
Discussion started by: dahlia84
7 Replies

4. Shell Programming and Scripting

Append && echo "success" to all commands

I am learning to build from SVN and other tools, with a lot of copying and pasting from forums. I like to append && echo "success" to all commands so that I can see at a glance if things went all right. Is there a way that I can have the bash shell append this to all commands? Thanks! (5 Replies)
Discussion started by: dotancohen
5 Replies

5. Shell Programming and Scripting

sed & areas respectively sed & pyramiding

Hello everyone, i wonder if someone could give me an advice regarding the following problem using sed. Given ist a structure as shown below: <aaa>text1<b>text2</b>text3<c>text4</c>text5</aaa> Now I want to change the outer tag from "aaa" to "new" and replace all tags inside the outer tags... (4 Replies)
Discussion started by: Donaldinho
4 Replies

6. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

7. Shell Programming and Scripting

Problems with Echo command

Hi there im having a problem with an echo command and have been trying to fix it for a little while now but just cant seem to see the issue. The code is as follows: #!/bin/bash #Filename: Assignment Author: Luke Francis echo "OPERATOR ADMINISTRATIVE TOOL" echo "Please enter your password:"... (4 Replies)
Discussion started by: warlock129
4 Replies

8. UNIX for Advanced & Expert Users

echo in ksh sh & bash

Hello, I have lib file which contain a function that get text to print on screen by echo command. Several scripts are inculde this lib and use this function. Each one of them is written in different shell language (sh ksh & bash). This causing some issues when using backslash charater as... (4 Replies)
Discussion started by: Alalush
4 Replies

9. What is on Your Mind?

[[ $(date +%Y) == 2007 ]] && echo "Happy New Year"

Same as the Title! :) (2 Replies)
Discussion started by: ripat
2 Replies

10. UNIX for Dummies Questions & Answers

combine 2 lines (command & echo)

does anyone know how to combine 2 lines? this is what im playing around with. (filename: online, user name: prml0001, real name: primal) #!/bin/sh who | grep $1 > /dev/null if then grep $1 /etc/passwd | cut -f 5, -d : echo is logged on exit 0 else grep $1... (13 Replies)
Discussion started by: primal
13 Replies
Login or Register to Ask a Question