sed on Mac OS versus Linux

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support sed on Mac OS versus Linux
# 1  
Old 06-07-2010
sed on Mac OS versus Linux

I'm trying to replace space with inderscore on Mac OS X 10.6.3
sed -i 's/ /_/g' somefile
sed: 1: "hsa_mirbase.fa": extra characters at the end of h commandThis works perfectly fine on Linux.
Thank you
Joseph Dhahbi
# 2  
Old 06-07-2010
Hi.

From the OSX man page for SED:

Code:
-i extension
  Edit files in-place, saving backups with the specified extension.

So, for example:
Code:
sed -i.bak 's/ /_/g' somefile

(I guess that the extension is optional on Linux, but may be provided (will check!))

(actually, without checking too much, according to the man page here, it is optional)

(actually #2, the OSX man page is rubbish! It suggests that it is optional, but complains when it's not given)

Code:
-i extension
             Edit files in-place, saving backups with the specified extension.  If a zero-length extension is given,
             no backup will be saved.  It is not recommended to give a zero-length extension when in-place editing
             files, as you risk corruption or partial content in situations where disk space is exhausted, etc.


Last edited by Scott; 06-07-2010 at 05:57 PM..
This User Gave Thanks to Scott For This Post:
# 3  
Old 06-07-2010
Thank you for your help
# 4  
Old 07-27-2010
SED on OS X is the BSD version (certainly is on OS X 10.6.4).

I have found that GNU versions of UNIX utilities often have far more options available to them, the danger is that if you know the extra options, you'll miss them on BSD based systems.

Ben
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simple sed command not working; could be a Mac/Linux vs. PC/Linux issue

Hello, I am on a Mac and trying to clean up some monthly files with a very simple SED: sed '3,10d;/<ACROSS>/,$d' input.txt > output.txt (from the input, delete lines 3 - 10; then delete from the line containing <ACROSS> to the end of the file) then output to output.txt Even when I try... (2 Replies)
Discussion started by: verbatim
2 Replies

2. Shell Programming and Scripting

GNU sed running on Mac

Super basic question. I installed sed GNU on a MAC running High Sierra. However, when I run sed '1i>sometext, I get the following error: sed: 1: "1isometext"; command i expects \ followed by text I have added the \ with no success. Is there anyway I can run sed and awk on MAC in the... (5 Replies)
Discussion started by: Xterra
5 Replies

3. Red Hat

Redhat versus Ubuntu Linux distribution

I am being asked to use RHEL red hat instead of ubuntu. Are the basic commands the same? I know the licensing is different, but are the package mangers/repositories the same? That is will sudo apt-get still be used? I have been using ubuntu for 4 years and have never used red hat so any... (5 Replies)
Discussion started by: cmccabe
5 Replies

4. Shell Programming and Scripting

Vm versus physical linux server

Does anyone have a script that can be run to tell you if you are on either a VM Linux or a physical Linux server? (15 Replies)
Discussion started by: bigbenn
15 Replies

5. UNIX for Dummies Questions & Answers

Mac OS X sed, add newline after pattern

Hi, I've been trying to work out how to add a new line to a file when the pattern matches .dmg. I've been searching Google but yet not found a working solution. Help would be appreciated... (9 Replies)
Discussion started by: pburge
9 Replies

6. Programming

fcntl works in linux but not in mac os x

Hi, Unless I am missing some serious differences in Mac and linux in terms of C programming, I dont know why this would happen. Please take a look at the following piece of code fragment: bool add_input_to_db(Cons *new_data) { // Set the attributes of the lock struct flock fl =... (3 Replies)
Discussion started by: newhere
3 Replies

7. UNIX for Dummies Questions & Answers

CTRL+H versus ^? versus BACKSPACE

Hi Gurus! I recently got my shell account (HP UX v11) created by our sysadmin and am having problem deleting with the backspace key. After doing some reading, I believe I need to enter a custom "STTY..." statement in my profile. Can someone please help me with the correct "STTY" sequence... (3 Replies)
Discussion started by: alan
3 Replies
Login or Register to Ask a Question