Find the answer to your Linux question:
Results 1 to 5 of 5
what utilility do i need to use to append text to the end of each word on each line of a text file?? example i have this: 2730031 cs592bu cs593bl ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! herot's Avatar
    Join Date
    Dec 2005
    Posts
    41

    how do i append text to each word in a file?


    what utilility do i need to use to append text to the end of each word on each line of a text file??

    example

    i have this:

    2730031
    cs592bu
    cs593bl
    751950pi
    3300021
    221789sbl
    cs589remp
    375002
    pc834or
    pc834pur
    pc834red
    cpb232
    383042go
    383044go
    45808bw
    21991
    21995f
    21998


    and i want to append .jpg at the end of each of these words... so that it looks like this (shortened):

    2730031.jpg
    cs592bu.jpg
    cs593bl.jpg
    ...

    just not sure what program or CLI utility can do this...

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I would use sed for that, like this:
    Code:
    sed 's/$/.jpg/'

  3. #3
    Just Joined! herot's Avatar
    Join Date
    Dec 2005
    Posts
    41
    ok thanks!

    so it would be

    sed 's/$/.jpg/' myfile

    correct?

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined! herot's Avatar
    Join Date
    Dec 2005
    Posts
    41
    that did it! thanks

  6. #5
    Linux User muha's Avatar
    Join Date
    Jan 2006
    Posts
    290
    Instead of typing away you can also save your sed commands in a script: http://wiki.linuxquestions.org/wiki/Sed#Sed_scripts

Posting Permissions

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