I have few files that I need to extract from the file extension and remove the number at the end of each file
test1.alarms
abcd1.alarms
test2.alarms
abcd2.alarms
Below is the code I used. The first part worked which removed the file extension and inserted back into the file, however, I was not able to remove the number of each file. After obtaining the result, I would then insert that back into the file.
for f in *.alarms; do
base=$(basename "$f" '.alarms')
sed --i "s/^/$base\:/" $f
db_name=`echo $base | grep -o [a-z]`
sed -ie "s/^/$db_name\:/" -i $f
done
result should be
test
abcd
test
abcd