3

I have some Grep find/replace commands working well under TextWrangler like the following one:

Find: (\"\d+.\d{3})+(\d{3}+[\s]+)

Replace: \1s

For example,this find/replace will replace:

TXTXTXT"123.123456 TXTXTXT by TXTXTXT"123.123sTXTXTXT

Now I want to do the same thing in command line by using egrep but it's not working:

egrep -e 's/(\"\d+\.\d{3})+(\d{3}+[\s]+)/\1s' -f m.txt > n.txt

egrep: Regular expression too big

Any idea? Thank you in advance.

user763308
  • 435
  • 2
  • 5
  • 10

1 Answers1

0

Your current problem is that the -f option reads the regular expression from a file. Just get rid of it. And lose the -e while you are at it. Just use:

egrep [regexp] [file] > [another file]

This, however, will leave you with another problem: grep just prints matches, it does not do substitutions. You should probably use sed instead.

qwertyboy
  • 1,576
  • 15
  • 25
  • Thanks for your reply. I try to use a grep command just because I have used the "grep mode" for the TextWrangler find/replace. Regarding sed, I made a little try but the syntax of the regex seems to be a little different. – user763308 May 24 '12 at 21:21
  • I do not know TextWrangler, but "grep mode" is often just a nickname for regular expressions in general. In fact, the "re" in the middle of "grep" stands for "regular expression" - the ed command "g/re/p" would search globally for a regular expression and then print it. Regular expressions are supported by many different tools, and their syntax often varies, but egrep (the e stands for extended regular expressions) and sed -r (the r stands for regular expressions extended, because -e was already taken) should be similar enough to manage. Give it a try. – qwertyboy May 25 '12 at 18:51