Visit The New, Modern Unix Linux Community

GNU sed running on Mac

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GNU sed running on Mac
# 1  
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 same way I do in linux?
# 2  
Originally Posted by Xterra
. . . when I run sed '1i>sometext, . . .

The absence of a second single quote makes it difficult to guess what exactly you want to do - a redirection, or inserting a <-gt> sign plus sometext?
Howsoever, for insertion, the man page says sed wants a "backslash <new line>" combination - try this and report back.
# 3  
sorry! My bad, I meant :
sed '1isometext' infile

Or even

echo a | sed '1isometext'

return the same error on MAC:

sed:  1:  "1isometext": command i expects \ followed by text

I can run either command in CygWin and add the "sometext" line to the first line in the infile no problem. I am trying to run all my sed scripts in MAC without any modifications

Last edited by Xterra; 10-07-2018 at 07:22 PM..
# 4  
As per the OSX sed manual (and the error message), you need to use a backslash and newline for a, i and c:
             Write text to the standard output.

So it should be something like this:
sed '1i\

# 5  
Using strings $(which sed) | grep "followed by text" on GNU sed returns nothing, whereas it does on macOS's standard sed.

So, even though you installed GNU sed, is that the one you are actually using? e.g. is that the first one you would find based on your PATH variable?
# 6  
e.g. is that the first one you would find based on your PATH variable?
That was the problem actually.
This User Gave Thanks to Xterra For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #275
Difficulty: Easy
OpenSolaris is the only version of the System V variant of UNIX available as open source.
True or False?

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert @Line # - SED (non-GNU)

Just posted on another fellow's question using ed, but I wanted to know about doing it with sed on Unix. For example - I have a file of an unknown length, but I want to add a line after the shell declaration (Line 2). If possible, I'd like the example to be able to just substitute in a number and... (2 Replies)
Discussion started by: Vryali
2 Replies

2. Shell Programming and Scripting

Unexpected results with lists in GNU sed

I have been living with this problem with GNU sed v4.1.4 for a long time, but now I really need to figure it out. When using a list in either an address or a search, the expression is matching lower and upper-case letters. works as it should. For example, if I run sed -nr "// p"... (7 Replies)
Discussion started by: nctrader
7 Replies

3. OS X (Apple)

GNU Sed Problem

Hi, I'm and Android developer using Mac OSX 10.7. I use Dsixda's Android Kitchen to develop my roms. I had it working fine on 10.6.8 and it still worked flawlessly when updating to 10.7. I installed Macports, and installed some packages, and then tried to run the Android Kitchen. I CD'd to the... (3 Replies)
Discussion started by: dmeadows013
3 Replies

4. UNIX for Dummies Questions & Answers

Is GNU sed installed?

Hi there, I'm new to UNIX and have the following question: At work a Solaris Unix system is used. I'm not sure if they have gnu sed installed so I tried using the command "sed -r" and got the error: "Illegal option --r" Does this mean that gnu sed is definitely not installed on the system... (8 Replies)
Discussion started by: js8765
8 Replies

5. Shell Programming and Scripting

gnu sed replace space with new line

please help in making sed singleline command i need to insert dos new line (CR LF) before " 34 matching device(s) found on \\cpu1." " 6 matching device(s) found on \\cpu7." " 102 matching device(s) found on \\mainserver." the problem is that sometimes there are both CR LF before strings and... (1 Reply)
Discussion started by: xserg
1 Replies

6. Shell Programming and Scripting

gnu sed regex grouping not working?

Hello, from the gnu sed manual, I should be able to do this: `\(REGEXP\)' Groups the inner REGEXP as a whole, this is used to: * Apply postfix operators, like `\(abcd\)*': this will search for zero or more whole sequences of `abcd', while `abcd*' ... (3 Replies)
Discussion started by: Allasso
3 Replies

7. UNIX for Dummies Questions & Answers

Running Terminal and/or X-Windows in Mac OS X

Quick question: When I load up Terminal or X-Windows on my Mac, and the prompt comes up...what folder am I starting in? (2 Replies)
Discussion started by: liquidcross
2 Replies

8. UNIX for Advanced & Expert Users

running linux ppc on a mac 7200

running linux ppc on a mac 7200... can someone please tell me how to do this... it says something about a red hat installer?? (2 Replies)
Discussion started by: ignus
2 Replies

Featured Tech Videos