i have a file with below content in linux:
servername: tesing1001
os: Unix
bu:
aid: 132
location: anywhere
environment: dev-stg
application: ABCD testing space
city: kk
I want to replace content in same file with below data:
servername: tesing1001
os: Unix
**bu: BLANK** **>>>>here since value is empty i will set it as BLANK hardcoded**
aid: 132
location: anywhere
environment: dev-stg
**application: ABCD_testing_space** **>>>>>here we will replace string space with "_"**
city: kk
all this thing we will do in same file . So, far i am trying to acheive above output with below logic
#!/bin/bash
cp -p /opsunix/dyfacter.txt /tmp/customized.txt.tmp
awk -F ":" '{
if ($2 == "")
{
print $0 " blank"
} else {
print $0
}
}' /opsunix/dyfacter.txt > /tmp/customized.txt.tmp && mv /tmp/customized.txt.tmp /opsunix/dyfacter.txt
with the help of above code, am able to identify null value and replace it with "blank" string.
servername: tesing1001
os: Unix
**bu: blank** **>>>>done**
aid: 132
location: anywhere
environment: dev-stg
**application: ABCD testing space** **>>>>>still need to correct**
city: kk
however 2nd last line i.e: application: ABCD testing space am not able to convert it as application: ABCD_testing_space.
appliying sed -i 's/ /_/g' /opsunix/dyfacter.txt is replacing all spaces in file after : .
purpose is to replace space in string .
Please help!