Shell script for file content manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lagunb
    New Member
    • Feb 2012
    • 1

    Shell script for file content manipulation

    Hello there, i'm a newbie for linux and need some help with a script. Basically what i need to do is;

    Below are links for pdfs to be opened and the links change dynamically as new content gets in

    ORIGINAL FILE CONTENT FORMAT
    ---------------------
    test1.pdf?123xy z
    test2.pdf?345xy z
    test3.pdf?456xy z

    FILE CONTENT FORMAT I NEED
    --------------------
    test1.pdf
    test2.pdf
    test3.pdf

    How can we make this happen by using "sed" command, i tried it but it seems i don't have enough knowledge.
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    If you just want to cut off strings after .pdf do like like that
    Code:
    cat you_file_with_links| sed 's/\(.*pdf\)\(.*\)/\1/g' >> new_file_with_links
    or
    Code:
    sed -i 's/\(.*pdf\)\(.*\)/\1/g' you_file_with_links
    first one is much safer because you do not overwrite original file. If you use second solution, make a backup of the file before

    Comment

    Working...