Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    23

    Unanswered: script with sed command

    Hello

    I'm trying to execute a script with sed command, but I'm having problems with the result. I need to change the content in a file in the string "name" with for the result of the command "ls" in a directory, but only need the position 21 to 24 from the name of the file. Is possible there are several files, so I need a loop.
    This is my script

    for i in `ls file*`
    do
    sed -e "s/name/echo `$i|cut -c 21-24`/g" /home/pp/jcl
    done

    Please can someone help me

    Thank you

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Syntax error!!!!
    The first backtick should be before the word "echo".
    Code:
    sed -e "s/name/echo `$i|cut -c 21-24`/g" /home/pp/jcl 
    
    should be
    
    sed -e "s/name/`echo $i|cut -c 21-24`/g" /home/pp/jcl

  3. #3
    Join Date
    Sep 2003
    Posts
    23
    Hello Kitaman

    I think that I'm a bit blind, I returned yesterday from vacation and I'm still a little out. Now it's working

    Thanks a lot

Posting Permissions

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