I have a file that contains filenames with absolute path.In the middle of that path, is a variable directory, whenever I hard code the variable part, it works fine, but when I replace it with the variable name, the sed part doesn't work.The sed part is to delete the pattern or for this matter, the path. file=`echo $one_file | sed 's:/dir1/dir2/$VAR/last_dir/::'`
Variable in sed
shell script;sed;filenames;quoting
When you use single-quotes, aka hard quotes, variable names are not expanded. You would need to use double-quotes, aka soft quotes.sed s:/dir1/dir2/$var/Last_dir/::or escape the quotes:sed 's:/dir1/dir2/'$var'/Last_dir/::'You would also need to be sure that $var does not hold any colon, dot, star, [, newline or backslash characters or that, if it does, they are escaped.