Find the answer to your Linux question:
Results 1 to 2 of 2
What shell script should i use to delete a line of text from a text file? The line is selected by a pattern defined by the user. I'll give this ...
  1. #1
    Just Joined!
    Join Date
    Dec 2006
    Posts
    2

    delete a line in a file with a shell script??

    What shell script should i use to delete a line of text from a text file? The line is selected by a pattern defined by the user.

    I'll give this example:
    File.txt

    qwerty;;12345
    asdfgh;;4567
    zxcvbn;;7890

    If i want to delete the second line i will give the following pattern:

    *456*, and then, the command will delete the whole second line.

    How can i do this with shell script?

    Thanks,
    Pedro

  2. #2
    Just Joined!
    Join Date
    Aug 2006
    Posts
    8
    mmm....
    I amn't sure if there is a simpler method. anyway sed comes in handy.

    sed '/<your expression>/d' (source file name) > tempfile
    cat tempfile > (source file name)
    rm tempfile

    File.txt
    qwerty;;12345
    asdfgh;;4567
    zxcvbn;;7890

    in our example:
    sed '/456/d' file.txt > tmpf
    cat tmpf > file.txt
    rm tmpf

    But this is a bit costly logic. Anyone to help out further?

Posting Permissions

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