I have predictable piped input, I want to iterate over each row and change two characters. the character positions are 19 and 20 (on every row.) The 19th character is a comma, I want to cut that. The 20th charater is a space, I want to replace it with an 'x'
775448167763476486, 783834143007506433, 35972, 35972,
775448167763476486, 844395243412914178, 408008, 408008,
775448167763476486, 891964514511355905, 8003, 8003,
783834143007506433, 891655551753846784, 66633, 66633,
Should become
715448167763476486x783834143007506433, 35972, 35972,
775448167763476486x844395243412911178, 408008, 408008,
705448167763476486x891964513511335905, 8003, 8003,
723834143007506433x891655551753846784, 66633, 66633
If there is an even simpler way to achieve the same effect, that'd be even better.
Edit.
So far I have tried a multitude of different approaches with
sed primarily..
sed 's/^ *([^,]*) //;s/, \([^,]*\),/\1x,/g'
As I understand is useful as looking for the first instance of a comma *([^,]*) I'm not sure of how the rest of the expression follows on after the ;
sed 's/, \([^,]*\),/\1x,/g'
I tried modifying the command this way but found an appended 'x' at the end of each row.
sed 's/\(.*\)\(.\{18\}\)\(.*\)/\1x\3/'
Same problem here. Two other expressions I tried to look at..
sed -E 's/^ *([^,]*) //
sed -e 's/\(.\)$/,\1/'
with the 'regular expression flag '-e' but to be honest I don't really understand what that means yet.
cut
cut -c-18 -c21-
When I tried this, the error I got was:
cut: only one type of list may be specified Try 'cut --help' for more information.
As I understand this is condensing or compressing with the '-c' flag, I'm assuming that the error might be related to the piped input coming from sed but I'm not sure, have to investigate with the man pages.
awk
awk '{gsub(/ /, "", $1); gsub(/ /, "x", $2); print}'
I felt this is a pretty clear way of seeing the idea of replacing whitespace with the desired charater, but had no effect on the input (unchanged.)
Which is why I posted here, not just looking for answers (sorry if the original post sounded like that, I just try to be brief and to the point.) Really just looking for ideas on how to approach such a problem.