I have a delimited text file (the delimiter is ';') where certain fields consist of many blanks e.g. ; ; and ; ;
Before I separate the data I need to eliminate these blanks altogether.
I tried the sed command using the following syntax:
sed -i 's/; *;/;;/g' <filename>
The * indicates that however many spaces are found between two semi-colons should be replaced by nothing so the string to replace with is an empty string surrounded by two semi-colons.
However I see that this only works on ASCII files whereas my files are ISO-8859. In these files this command doesn't detect multiple spaces with the * character.
Corona688's code uses semicolon as a field separator and specifies an awk script to read input from inputfile and write output to outputfile . Your version of his script uses his entire awk script as a field separator.
That was exactly it. With just the semicolon the command failed and I thus though maybe Corona had left the semi colon after awk inadvertently.
Now that I've put the semicolon within quotes, it works like a charm.
Thanks Corona, Don & MadeInGermany.
I do have a last question though - is it possible to maintain the same filename with a single command? That is erase the file with the blanks trimmed and name it as the original file without having to go through multiple steps like delete original file and rename new file as original?