Results 1 to 5 of 5

Thread: sed question

  1. #1
    Join Date
    Jan 2006
    Beans
    182

    sed question

    Hi I am trying to write a sed one liner which will look for the following line in a file:
    action "record-stream" {
    and replace the line following the above line (whatever it might be) with:
    tab space followed bycommand "x-terminal-emulator -e streamripper %q -d /home/jack/ripped -r -q";
    how can I do this?
    Thanks in advance.
    -Jack

  2. #2
    Join Date
    Oct 2006
    Beans
    144

    Re: sed question

    this should work,
    say there is file call sed.txt, in file is your text from your post.
    action "record-stream" { hello
    then at propmt type:
    cat sed.txt | sed 's/action "record-stream" {/\tcommand "x-terminal-emulator -e streamripper %q -d \/home\/jack\/ripped -r -q";/g'
    this produces:
    Code:
           command "x-terminal-emulator -e streamripper %q -d /home/jack/ripped -r -q"; hello

  3. #3
    Join Date
    Jan 2006
    Beans
    182

    Re: sed question

    Quote Originally Posted by bradleyd View Post
    this should work,
    say there is file call sed.txt, in file is your text from your post.
    action "record-stream" { hello
    then at propmt type:
    cat sed.txt | sed 's/action "record-stream" {/\tcommand "x-terminal-emulator -e streamripper %q -d \/home\/jack\/ripped -r -q";/g'
    this produces:
    Code:
           command "x-terminal-emulator -e streamripper %q -d /home/jack/ripped -r -q"; hello
    Hi thanks for the reply and help.. but this is not exactly what i wanted.
    Let's say we have the following two lines in the file (among many other lines):
    action "record-stream" {
    command " ";
    what i want sed to do is replace
    command " ";
    with the string I pasted, when it finds
    action "record-stream" {
    The operative point here is that
    command" ";
    comes exactly on the next line after
    action "record-stream" {
    and this is where
    command " ";
    needs to be replaced.

    With your code, it's replacing
    action "record-stream" {
    and keeping
    command " ";
    Hence it is appearing as follows:
    command "x-terminal-emulator -e streamripper %q -d /home/jack/ripped -r -q";
    command " ";
    Last edited by jackrobinson; March 29th, 2007 at 02:10 PM.

  4. #4
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: sed question

    If you don't mind perl instead of sed:
    Code:
    perl -i.save -p -0 -e 's/(action "record-stream" {\n)(.*)\n/$1\t command "x-terminal-emulator -e streamripper \%q -d \/home\/jack\/ripped -r -q";\n/g'  filename
    This will make the changes in filename. A copy of the original will be saved in filename.save.

  5. #5
    Join Date
    Oct 2006
    Beans
    144

    Re: sed question

    if you are still interested in sed this should be what you were looking for(as far as I can understand)
    Code:
     cat sed.txt | sed -e '/action "record-stream" {/ a\  command "x-terminal-emulator -e streamripper %q -d \/home\/jack\/ripped -r -q";/' -e '/command "";/d'
    not the most elegant but gets the job done. WW perl's one liner works great too.
    B

Bookmarks

Posting Permissions

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