LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-11-2013, 11:12 AM   #1
mactruck
LQ Newbie
 
Registered: Jan 2013
Posts: 3

Rep: Reputation: Disabled
SED help with first character in line.


So I have this sed command that will replace " l " with " I " and fix many other l and I mistakes. I have this script running through subtitles and it has worked great so far. The problem that I am running into is when the first letter is a lower case L and should be and upper case I.

Code:
6
00:01:28,172 --> 00:01:30,506
l vant to kiss your tush.
now my sed command will not work because there is no space before the l.

Code:
sed 's/ l / I /g' $i.b > $i.a

Is there a way I can have it change l to I if its at the beginning of a sentence?

Thanks

mac
 
Old 01-11-2013, 11:21 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,493

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Simply tell sed that you may have leading space(s) (and perhaps trailing ones) or you can have a look at word boundaries.

Check here for more information.
 
Old 01-11-2013, 11:21 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
To get the most out of commands like sed, you should learn how to use regular expressions. In this case you "anchor" the pattern to the beginning of the line with "^".

Code:
sed 's/^l /I /g' "$i.b" > "$i.a"
You can probably also combine a lot of your patterns with character ranges and backreferences.


Here are a few regular expressions tutorials:
http://mywiki.wooledge.org/RegularExpression
http://www.grymoire.com/Unix/Regular.html
http://www.regular-expressions.info/
 
Old 01-11-2013, 11:39 AM   #4
mactruck
LQ Newbie
 
Registered: Jan 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks, that worked.
 
  


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
[SOLVED] sed help - replace line feed with different character bradvan Programming 7 04-22-2012 11:31 PM
[SOLVED] insert a character in line using sed/awk sunilsagar Programming 3 07-26-2011 01:44 AM
sed add a character to the end of each line keenboy Linux - General 2 08-05-2010 12:36 PM
removing new line character using sed Fond_of_Opensource Linux - Newbie 4 03-26-2010 02:19 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 12:06 PM.

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