Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-30-2012, 04:01 PM   #1
LQ Newbie
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
Sed command - command garbled errror

I am a lerner to sed.Was just trying to run the following command on solaris:

echo "NotWorking" |sed s/[a-z]/\(&\)/

Basically want to add to every char with '( )' but i get command garbled error.

Need help.
Old 03-30-2012, 04:18 PM   #2
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,735

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
Not sure about Solaris, but on Linux you need '-e' before your substitution to tell it to execute the following script.
1 members found this post helpful.
Old 03-30-2012, 08:02 PM   #3
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Originally Posted by smallpond
Not sure about Solaris, but on Linux you need '-e' before your substitution to tell it to execute the following script.
You can use -e, but it's not a requirement. I find that it can help to break up multiple, independent patterns with multiple -e options just to make things easier to understand, but for quickie one-liners, I rarely use the -e switch.

Also, I'm not too familiar with Solaris. My main suggestion though is you should enclose your sed script in quotes. This prevents the shell from looking at your script and trying to find job control/wildcard characters to interpret or expand. For bash, the '&' character (among others) is a job control character meaning to send the command to the background. Using quotes also saves you from a lot of backslash-escaping.

For instance:
user@localhost$ echo "NotWorking" | sed 's/[a-z]/(&)/'
As you can see, the sed substitution takes place only once. Your original goal is to add the parentheses around each (lowercase?) character, then something like:
user@localhost$ echo "NotWorking" | sed 's/[a-z]/(&)/g'
Lastly, if you truly wanted parentheses around every character:
user@localhost$ echo "NotWorking" | sed 's/[a-zA-Z]/(&)/g'

Last edited by Dark_Helmet; 03-30-2012 at 08:04 PM.
1 members found this post helpful.
Old 03-30-2012, 10:04 PM   #4
LQ Newbie
Registered: Mar 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks smallpod and Dark_Helmet - It did worked on Linux but the same command did not work on solaris.Thanks i could try it on my home linux machine.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
make command gives errror message revathhy Linux - Newbie 27 10-03-2013 07:17 AM
Modifying text file with "one command line" SED command... daleo Linux - Newbie 3 01-13-2012 05:32 AM
Chinse character printed garbled when printing through lp command amit_pansuria Linux - General 1 07-29-2009 09:48 PM
less command response is garbled amit_pansuria Linux - General 2 06-16-2008 05:13 PM
'sed: command garbled:' error on Solaris fatjack Solaris / OpenSolaris 3 08-25-2006 05:15 PM

All times are GMT -5. The time now is 08:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration