LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SED help with first character in line. (https://www.linuxquestions.org/questions/linux-newbie-8/sed-help-with-first-character-in-line-4175445157/)

mactruck 01-11-2013 11:12 AM

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

grail 01-11-2013 11:21 AM

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.

David the H. 01-11-2013 11:21 AM

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/

mactruck 01-11-2013 11:39 AM

Thanks, that worked.


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