0

I have a file with 1000's of rows looking like

"20140611","20:19","C","IT","IT","HDR","HDPDIT","675605","000000135.97"," ..........

I am trying to replace all occurrences of string that matches this pattern : quote then 6 numerics followed by a closing quote ( i.e. "675605" with "675605@")

Using edit plus regular expression search and replace, the search string is :

\"[0-9][0-9][0-9][0-9][0-9][0-9]\"

This will find all the occurrences I need

However I'm unable construct the correct replace with reg ex to replace the match with itself followed by the @ sign e.g. "675605@

0

4 Answers 4

1

With sed you can have:

sed -r 's|"([0-9]{6})"|"\1@"|g' file

Add -i to modify it inline.

So my proposed regex - replacement form is:

"([0-9]{6})" - "\1@"

Quoted:

\"([0-9]{6})\" - \"\\1@\"
Sign up to request clarification or add additional context in comments.

Comments

1

Regex:

\"([0-9][0-9][0-9][0-9][0-9][0-9])\"

Replacement string:

"\1@

DEMO

Replacement string would be "\1" if you want "675605@"

Comments

0

You need to use capturing groups. I don't know if you can use them in Edit Plus, but I think it should work:

Find what: \"(\d{6})\" Replace with: \"\1@\"

Where \1 is a number captured in parenthesis.

Comments

0

Open your file in vim or vi editor using below command:

vi "filename"

then use this command it replace your "675605" pattern with "675605@" :%s/675605/675605@/g then esc :wq now you open your file it replaced all your "675605" pattern with "675605@".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.