I want to modify a line if a specific keyword is found in a line.
CS_CODE, SM_NUM, PORT_NUM, DEV_PORT_NUM, DIRNUM, MAIN_DIRNUM, BILL_NO, ADR_NAME
In above line, if 'PORT_NUM' is present then 'BILL_NO' should be replaced with 'NA'. Only the keyword present in the line should be replaced.
I am using below approach:
while IFS=$'\n' read -r line
do
if [[ $line == *"$string"* ]]; then
< sed command to replace only keyword >
fi
done < "$file"
How can I achieve this?
Note: '-i' extension does not work in my sed version.
sed '/PORT_NUM/ s/BILL_NO/NA/' >new_file
... – jasonwryan Mar 31 '15 at 07:47sed
answers... – Nathan McCoy Mar 31 '15 at 11:39