Portion of my dataset which is pipe delimited csv file:
|B20005G |77|B20005G 077|$2,500 to $4,999|
|B20005G |78|B20005G 078|$5,000 to $7,499|
|B20005G |79|B20005G 079|$7,500 to $9,999|
I match the lines of the third field with this sed expression:
sed -n '/|[[:alnum:]]\{7\} [[:digit:]]\{3\}|/p'
Now, is there a way to tell sed to delete space in the third field to get this:
|B20005G |77|B20005G077|$2,500 to $4,999|
|B20005G |78|B20005G078|$5,000 to $7,499|
|B20005G |79|B20005G079|$7,500 to $9,999|
with a regex like this
\([[:alnum:]]{7}\) \([[:digit:]]{3}\)
defines two groups, the ones between \( \)
, which we can refer to in the substitution via \1
, \2
, so
sed -n 's/\([[:alnum:]]\{7\}\) \([[:digit:]]\{3\}\)/\1\2/' myfile.txt
which gets rid of the space in between the two groups.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments