LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 03-30-2012, 04:01 PM   #1
gauavmahesh
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.
Thanks
 
Old 03-30-2012, 04:18 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 1,602

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
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
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
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:
Code:
user@localhost$ echo "NotWorking" | sed 's/[a-z]/(&)/'
N(o)tWorking
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:
Code:
user@localhost$ echo "NotWorking" | sed 's/[a-z]/(&)/g'
N(o)(t)W(o)(r)(k)(i)(n)(g)
Lastly, if you truly wanted parentheses around every character:
Code:
user@localhost$ echo "NotWorking" | sed 's/[a-zA-Z]/(&)/g'
(N)(o)(t)(W)(o)(r)(k)(i)(n)(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
gauavmahesh
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.
 
  


Reply


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 01:35 AM.

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