Issue
I get the set of strings as input in terminal. I need to replace the ".awk"
substring to ".sh"
in each string using shell and then output modified string.
I wrote such script for doing this:
#!/bin/bash
while read line
do
result=${line/.awk/.sh}
echo $result
done
But it gives me an error: script-ch.sh: 6: script-ch.sh: Bad substitution
.
How should I change this simple script to fix error?
UPD: ".awk"
may be inside the string. For example: "file.awk.old"
.
Solution
Not sure why it works for you and not for me.. might be the input you're giving it. It could have a space in it.
This should work:
#!/bin/bash
while read line
do
result=$(echo $line | sed 's/\.awk/\.sh/')
echo $result
done
Answered By - Mike Furlender