ehime
ehime

Reputation: 8375

SED / AWK multi-file replacement?

I've been trying to figure out a command that will search through 13+ files and replace all matches and variances of forms data and replace them with form data enhancements.

The trick is that there could be [whitespace] - or _ as a separator that I would like to preserve. I'm running form command line so I believe I could run this script multiple times and just point it at the file, or if there's a way to capture all files in a directory (even including directory names) it might just be easier.

I believe its something to the tune of

sed "s/forms_data/form-data-enhancements/g ; s/forms-data/form-data-enhancements/g ; s/forms data/form data enhancements/g" oldfile > newfile

nut I'm not sure.....

variances might be

forms-data

forms_data

forms data

etcetra. Would someone mind sharing a bit of sed awk wisdom? The best I can find is something called an arrary replace but was unable to get any information on how to use it.

Thanks greatly.

Upvotes: 2

Views: 780

Answers (1)

jaypal singh
jaypal singh

Reputation: 77085

Will this work for you -

sed -i 's/\<forms[ -_]data\>/form data enhancements/g' /path/to/files*

-i will do in-file substitution. So first pick a file and run the command without the -i option. If everything looks ok then you can go ahead and use the -i.

Update:

If you would like to retain the separators then you can do something like this -

sed -i 's/\<forms\([ -_]\)data\>/form\1data\1enhancements/' /path/to/files*

Upvotes: 3

Related Questions