#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    3
    Rep Power
    0

    sed command problem


    hi all. pls help.

    i am using the sed command to substitute several text patterns in a file. my problem is, i want to replace the pattern with a new line. i cant seem to make \n work. here's an example. the patterns to be replaced with a next line are "abc", "def" and "hij".

    input file:
    qwertyabcuiop asdfgdefhjkl hijzxcvbnm

    output file shoule be like this:
    qwerty
    uiop asdfg
    hjkl
    zxcvbnm

    thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    137
    Rep Power
    0
    To my knowledge, \n doesn't work in sed. But you can spilt lines:

    Code:
    #!/bin/bash
    
    echo "This is a test sentence" | \
    sed -n 's/This is\(.*\)/This is\
    \1/p'
    => This is\(.*\)
    Searchpatern.

    => This is\
    => \1
    Output patern. The \ after is is there for the linebreak, the \1 prints all that was captured with the \(.*\).

IMN logo majestic logo threadwatch logo seochat tools logo