Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I want to delete lines in a file before the first occurence of a set of words. I use the command "sed". How I can do this? Thanks Marco...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2013
    Posts
    4

    Delete lines with sed


    Hi,
    I want to delete lines in a file before the first occurence of a set of words.
    I use the command "sed".
    How I can do this?

    Thanks
    Marco

  2. #2
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    can you give an example? are the lines always going to be the same?

  3. #3
    Just Joined!
    Join Date
    Mar 2013
    Posts
    4
    The file is a SQL script.
    Example:

    CREATE TABLE xxx .....
    CREATE TABLE yy ...
    ....
    CREATE VIEW zz..

    I want to delete all the lines before the statement "CREATE VIEW zz".
    The dimension of the file is variable.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    I dont know how to do this with sed..... I would use grep -v "CREATE TABLE"

  6. #5
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    226
    hi,

    Code:
    sed ':c;/CREATE VIEW zz/!{N;bc};s/.*\n//g' $urFile

Posting Permissions

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