Using variable with the sed command

Asked

Viewed 1,783 times

8

I have the following occurrence:

DirUpload=/var/log
find $DirUpload | sed 's/$DirUpload//g'

The question is, how to use variable along with sed?

2 answers

6


According to the response of Soen:

DirUpload=/var/log
find $DirUpload | sed "s|$DirUpload\/||g"
  • Use double quotes to expand variables
  • Use a different tab than / (in the example: |)

3

Just use double quotes instead of single quotes:

  DirUpload=/var/log
  find $DirUpload | sed "s/$DirUpload//g"
  • 1

    In doing so ai gives the following return: (sed: -e expression #1, char 9: Unknown option to `s')

  • What you’re looking to replace in the files he finds ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.