Hi,,
I have the line below in a file:
$!VarSet |LFDSFN1| = '"E:\APC\Trials\20140705_427_Prototype Trial\Data\T4_20140705_Trial_Cycle_Data_13_T_Norm.txt" "VERSION=100 FILEEXT=\"*.txt\" FILEDESC=\"General Text\" "+""+"TITLE{SEARCH=NONE NAME=\"New Dataset\" LINE=1
I want to write a script to change it to:
$!VarSet |LFDSFN1| = '"T4_20140705_Trial_Cycle_Data_13_T_Norm.txt" "VERSION=100 FILEEXT=\"*.txt\" FILEDESC=\"General Text\" "+""+"TITLE{SEARCH=NONE NAME=\"New Dataset\" LINE=1
i.e remove the section of the file path.
E:\APC\Trials\20140705_427_Prototype Trial\Data\
The file path and the file names are varibels defined by
DATA_FILE_NAME=$(awk -F'"' -v VAR="$FILE" 'NR==4 {print $2}' $FILE)
giving me : E:\APC\Trials\20140705_427_Prototype Trial\Data\T4_20140705_Trial_Cycle_Data_13_T_Norm.txt
DATA_FILE_NAME_NO_PWD=$(echo $DATA_FILE_NAME | awk -F'\' '{print $NF}')
giving me: T4_20140705_Trial_Cycle_Data_13_T_Norm.txt
I wanted to use SED to replace $DATA_FILE_NAME with the $DATA_FILE_NAME_NO_PWD, however I can't get it to work. I know its due to the / in the variable $DATA_FILE_NAME however i can't work out how to escape this character. I've tried as many ways as i can find, but still can't get it to work.
How do i get this to work, what have i missed?
sed -i "s|$DATA_FILE_NAME|$DATA_FILE_NAME_NO_PWD|" "$FILE"