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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command works on Fedora/Ubuntu, but doesn't work in Mac
# 1  
Old 12-07-2011
sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question.
I define a function using sed command:

Code:
replace()
{
searchterm=$1
replaceterm=$2
sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp'
mv $WORK'tempfile.tmp' $3
}

Then I call
Code:
replace 'test = 0' 'test = 1' $myfile

This code works well in both Ubuntu and Fedora, but when executing the script in Mac, the following error occured:

Code:
sed: 1: "s/test = 0/test = 1/ig\n": bad flag in substitute command: 'i'

Unfortunately, I don't have a Mac to test. Can anybody tell me how I should modify the source to make it work in Mac as well. Thanks in advance.
# 2  
Old 12-07-2011
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

PING to AIX works but TELNET FTP SSH doesn't work

root@PRD /> rsh DR KFAFH_DR: protocol failure due to unexpected closure from server end root@PRD /> telnet DR Trying... Connected to DR. Escape character is '^]'. Connection closed. root@PRD /> ftp DR Connected to KFAFH_DR. 421 Service not available, remote server has closed connection... (2 Replies)
Discussion started by: filosophizer
2 Replies

2. Solaris

Drop_caches doesn't work on Solaris but works on RHEL6

Hello Experts, I am performing performance tests on a few mysql select queries. I use the following command to clear the memory disk caches. sync && echo 3 | sudo tee /proc/sys/vm/drop_caches I however see that the above command works on RHEL6 but doesn't work on Solaris 10. I asked... (4 Replies)
Discussion started by: Anirudh Kumar
4 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' $myfileThis code works well in... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

4. Shell Programming and Scripting

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... (7 Replies)
Discussion started by: andreirp
7 Replies

5. Shell Programming and Scripting

Replace string with sed doesn't work

Hello, Unfortunately I don't found any working solution for my problem :/ I have pass file for dovecot authorizing in this format: user@domain.tld:{SSHA}Ykx2KVG/a2FKzjnctFFC2qFnrk9nvRmW:5000:5000:::: . . ...Now, I want to write some sh script for password changing for grep'ed user, in... (5 Replies)
Discussion started by: vincenty
5 Replies

6. Ubuntu

Microphone doesn't work in Ubuntu 10.04

When I try to speak to the microphone, there is no echo in the speaker. I test it again by dialing Skype, there is still no sound in my side while I can hear the other side. What can I do? Thanks in advance! (4 Replies)
Discussion started by: i2000s
4 Replies

7. Shell Programming and Scripting

cd command doesn't work through variables

Hi.... cd command is not working when dual string drive/volume name is passed to cd through variables....... For Ex.... y=/Volumes/Backup\ vipin/ cd $y the above command gives error....... anyone with a genuine solution ? (16 Replies)
Discussion started by: vipinchauhan222
16 Replies

8. Shell Programming and Scripting

Command doesn't work under cron ?

I have defined in cron crontab -l >/FIXENGINE/data/crontab.$(whoami).$(date +%a) The resulting file is named crontab.fixadmin. When I run the above from a command line, the file is named: crontab.fixadmin.Tue (or whatever day I happen to be running) The question is - why do I get... (4 Replies)
Discussion started by: bigjohn-nj
4 Replies

9. Shell Programming and Scripting

sed doesn't work

Hello I' m confused a bit. I want to replace string "&amp" with "&" using this command. sed 's/&amp/&/g' and it doesn't work. Nothing happens. On the other side this works: sed 's/&amp/@/g' or sed 's/&amp/^/g' !!! Can somebody help please? Thanks (3 Replies)
Discussion started by: billy5
3 Replies

10. Shell Programming and Scripting

command line work script doesn't

Hello, I'm stuck and confused as to why when I execute things form the command line it works but when in a script it doesn't. My script: ### creating a lock on the console touch /var/run/console.lock chmod 600 /var/run/console.lock echo "$User" >>... (2 Replies)
Discussion started by: larry
2 Replies
Login or Register to Ask a Question