bash - append given variable in stream of cpp files using awk/sed by ignoring backslash -
i have variable in shell script follows:
var=file1.cpp file2.cpp file3.cpp file4.cpp
i want append "folder/subfolder/
" every .cpp file. use following sed
command helps partially:
echo $var | sed 's/^/'"$i"'\//g;s/\s/ '"$i"'\//g' $i --> "folder" , sed adds "/"
this sed
able append "folder/
" files.... unable append "folder/subfolder
" every file.
how can modify sed add "folder/subfolder/" path files. can modify somehow ignore backslash "/ " in $i
variable ( i.e. ignore "/" in folder/subfolder
you can use different delimiter sed
#
also can combine s
command single sed
example
$ echo $var | sed -r 's#(^| )#\1folder/subfolder/#g' folder/subfolder/file1.cpp folder/subfolder/file2.cpp folder/subfolder/file3.cpp folder/subfolder/file4.cpp
or
if want use variables inside sed
$ re="folder/subfolder/" $ echo $var | sed -r "s#(^| )#\1$re#g" folder/subfolder/file1.cpp folder/subfolder/file2.cpp folder/subfolder/file3.cpp folder/subfolder/file4.cpp
Comments
Post a Comment