how to “translate” Grep find/replace commands working with TextWrangler by a command line

StackOverflow https://stackoverflow.com/questions/10744637

  •  10-06-2021
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top