sed replace regular expression match

Dmitry Buzolin

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|
Shawn Mehan

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

regular expression in sed replace question mark

From Java

Regular expression selectively match

From Dev

How to use sed to replace only on lines matching a regular expression?

From Dev

Regular Expression Following Match

From Dev

How to replace a string in a regular expression match

From Dev

sed regular expression failure

From Dev

Using sed, how can a regular expression match Chinese characters?

From Dev

sed with regular expression

From Dev

Regular Expression Match - Javascript

From Dev

replace text with regular expression keeping structure match on sublime text

From Dev

ruby match regular expression

From Dev

the use of "+" in sed regular expression

From Dev

Regular expression to match | but not ||

From Dev

Regular Expression (Replace) only first match

From Dev

MSVC regular expression match

From Dev

How to match everything but a regular expression with sed?

From Dev

Replace all occurrences that match regular expression

From Dev

Replace all occurrences that match regular expression

From Dev

the use of "+" in sed regular expression

From Dev

Regular expression with sed

From Dev

Why regular expression doesn't match input with sed command

From Dev

sed regular expression extraction

From Dev

sed command with regular expression

From Dev

How to match everything but a regular expression with sed?

From Dev

Vim: Replace regular expression match on a line with another regular expression match from same line

From Dev

Negation of sed regular expression

From Dev

Sed Regular Expression with /P

From Dev

C# Regular Expression and Replace on part of the match

From Dev

+ Regular Expression not working in sed

Related Related

HotTag

Archive