Thread: Sed script

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    319
    Rep Power
    8

    Sed script


    Hi,

    why this small sed script is printing abcdef55swerer55er ? Isn't it supposed to print only abcdef ??

    PHP Code:
    -bash-4.1
    echo 
    abcdef55swerer55er|sed 's/\([a-zA-Z]*\) \([a-zA-Z]*\) /\1 /' 
    abcdef55swerer55er 
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Sed Script


    Originally Posted by sangfroid
    Hi,

    why this small sed script is printing abcdef55swerer55er ? Isn't it supposed to print only abcdef ??

    PHP Code:
    -bash-4.1
    echo 
    abcdef55swerer55er|sed 's/\([a-zA-Z]*\) \([a-zA-Z]*\) /\1 /' 
    abcdef55swerer55er 
    If I'm reading this correctly, you are asking sed to match any number of characters from the group a-zA-Z followed by the same and then with the back reference replace them with the same letters. Any other characters will just pass thru unchanged.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,200
    Rep Power
    14
    in your sed you use a 'space' as trailor AND you have no 'spaces'

    echo abcdef55swerer55er|sed 's/\([a-zA-Z]*\)\([0-9]\).*/\1/'

    prints: abcdef
    working on Solaris[5-9], preferred languages french and C.

IMN logo majestic logo threadwatch logo seochat tools logo