LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2010, 06:02 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,898

Rep: Reputation: 55
sed


Hi:

~$ sed s/^bb/bbbbbb/ foo1.txt
~$ sed: -e expression #1, char 3: unterminated s command
~$

where 'b' stands for space. Can somebody tell what is the error here? Sed is running under bash. Thanks.

Last edited by stf92; 07-18-2010 at 06:36 AM.
 
Old 07-18-2010, 06:08 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 17,066

Rep: Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594Reputation: 2594
Char 3 maybe ?.
Delineate the substitution - either single or double quotes should do.
 
1 members found this post helpful.
Old 07-18-2010, 06:08 AM   #3
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Check your quoting. At least, the shell will interpret whitespaces as delimeters for arguments, so your regular expression is split up and results in garbage.

And, even with correct quoting, this expression will replace any space at the beginning of a line with a space -- de facto a no-op, probably not what you want.
 
1 members found this post helpful.
Old 07-18-2010, 06:42 AM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,898

Original Poster
Rep: Reputation: 55
Thanks. By the way, I edited my post, because LQ's editor won't allow me to write several spaces together. I did not see that. My fault.
 
Old 07-18-2010, 06:43 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392
@stf92: Don't edit your original post after people have answered but make a new entry. The answers given might not make any sense any more if you edit the original post......

If you need to change any kind of whitespace at the beginning of the line you can use [:blank:] or [:space:] like this:

sed 's/^[[:blanl:]]/X/' foo1.txt

Substitute X with the char(s) you want/need.

Hope this helps.
 
Old 07-18-2010, 06:45 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392
Hi,

Quote:
Originally Posted by stf92 View Post
Thanks. By the way, I edited my post, because LQ's editor won't allow me to write several spaces together. I did not see that. My fault.
You can use multiple spaces when using the code tags (remove the spaces to make it show):
[ code ] text goes here [ /code ]

Example:
Code:
1 2  3   4    5     6
Hope this helps.

EDIT

Have a look here for all the possible tags: BB Code List

/EDIT

Last edited by druuna; 07-18-2010 at 06:48 AM. Reason: Added BB code url
 
1 members found this post helpful.
Old 07-18-2010, 07:45 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,898

Original Poster
Rep: Reputation: 55
Hi:

thanks for both the sed example and the use of the [code] tags. The BB code list is very instructive. I took notice of your advice about editing the OP. Regards.
 
  


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
sed - use sed to replace multiple instances from "x" to "y" in a line mrodmac Linux - General 4 02-02-2010 11:37 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:11 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration