I store files named like this: word-word2-word3-word4.txt . The number of "words" varies from file to file.
I want to replace certain of the dashes with pluses e.g word+word2-word3+word4.txt
I want to specify the dashes or minus-signs to change by typing in numbers.
I have an awkward script that doesn't work - it does this:
- dashes are supplemented with a semi-colon for later awk splitting purposes
- user types in numbers specifying dashes to replace
- numbers are appended to end of filename e.g aaa-;bbb-;ccc.txt 1 3
- and piped into awk for processing
- in awk, make an array of the appended numbers,
- and an array of the words with a split on the first field
- then gsub ';' for '+' on the split array using the number array to specify the index
Here is my grisly script which hardcodes the filename for the purposes of quick fiddling and trialing. I can't think how to exit the awk script usefully. The plan is to exit awk and do a final substitution in sed.
I am quite aware this is a dogs dinner of a script displaying plenty of poor-learning. Nevertheless, please offer any help if you are disposed to.
file='wot-;wit-;wet-;wat.txt';
echo -n "type digits";
read nos; varr=$(echo $nos);
newfile=$(echo $file $varr);
echo "$newfile" | awk '{ for (i=2; i<=NF ;i++) arr[i]=$i}
END{ split($1,spl,"-");
for( var in arr ) gsub(";","+", spl[var]);
print THIS IS NOT WORKING - CAN'T GET ANYTHING USEFUL OUT }'