Find the answer to your Linux question:
Results 1 to 5 of 5
in a huge text we want all of the :tho becomes you thou becomes you thy becomes your thine becomes your and we should change Tho to You also the ...
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    16

    AWK script replacing words in a text

    in a huge text
    we want all of the

    :tho becomes you
    thou becomes you
    thy becomes your
    thine becomes your
    and we should change Tho to You
    also
    the case that tho with a punctuation such tho, should be you,

    basically i writer down something like this

    awk '
    {

    for(i=1;i<=NF;i++)
    {

    if (($i == "thee")||($i == "thou"))
    {
    printf("you")
    }
    else if (($i == "Thee")||($i == "Thou"))
    {
    printf("You")
    }
    else
    {
    printf $i
    }
    printf " "
    }
    print ""
    }'

    There are two problems :
    one is that it doesn't work fine with punctuation
    second is that after the job done, it will leave a extra blank at the end of each line.

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    perhaps the stream editor "sed" is better suited for this

    if "text" is the name of your long text, then something like this
    might work:

    sed 's/thee/you/;s/thou/you/;s/Thee/You/;s/Thou/you/' <text

    this does what your "awk" script does
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    Jun 2010
    Posts
    16

    Unhappy

    Thx but the queestion asks me to make a awk script

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by ionguang View Post
    Thx but the queestion asks me to make a awk script
    Sorry no homework questions.
    Make mine Arch Linux

  5. #5
    Just Joined!
    Join Date
    Jun 2010
    Posts
    16
    want the get idea.
    how this would work
    $i == thou[unct:]?

    $i == "thou," | "thou." | "thou" etc etc

Posting Permissions

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