I am trying to replace string into number from the file So, I have variable &FLOW which need to change to 001, ex :
cat file.txt
This is file ' PISP &FLOW'
PISD.DATA.CYCLE&FLOW..ONE
desired output
This is file ' PISP 001'
PISD.DATA.CYCLE001.ONE
I tried below commands in a script :
for item in file.txt
do
sed 's/\&FLOW/\./001/g' $item
sed 's/\&FLOW/001/g' $item
done
It is giving error. The second sed command is working, but I need to run first the beginning sed command otherwise after running first the second sed command, it would ignore the beginning sed command.
Any help would be appreciated!
itemto to literal stringfilename, but the file you show as example input is calledfile.txt, so that won't work, for starters.sedcommands, you may chain them likesed 's/1/2/g;s/3/4/g'. However, your patterns are so similar, they only differ in 1 char, so you may make it optional and use a single pattern. More importantly, you did not actually modify file contents, you need to pass the-i(inline) option. See my answer below with explanations of the pattern and how to use-iwith both Linux (GNU) and Mac OS (FreeBSD)sed.