Find the answer to your Linux question:
Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187

    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

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,222
    There is a way to match word beginnings without having to put a space in front. I suggest you have a look at this tutorial which has a section on matching words as well as a lot of other useful tips.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  3. #3
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    Thanks hazel, It looks like I would want to use something like

    "\<l\>" "\<I\>" but how would I use that in a sed command? Or should I use a tr command?

  4. #4
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,222
    Quote Originally Posted by mactruck View Post
    Thanks hazel, It looks like I would want to use something like

    "\<l\>" "\<I\>" but how would I use that in a sed command? Or should I use a tr command?
    well, you won't need the quote marks as you are already using single quotes. You do need the backslashes; they are part of the code. So \<l would mean "l at the beginning of a word". But it might not work; that tutorial was written for Solaris users and the Solaris utilities don't always work the same way as the GNU utilities that Linux uses, especially where regular expressions are concerned. As they say, your mileage may vary.

    If it doesn't work, there are other ways. I would use " l|^l" to specify that l must occur either after a space or at the beginning of a line.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •