danielbmartin |
01-14-2012 02:29 PM |
sed - prefixing a character string identified by a RegEx
I want to insert a fixed character string immediately before a target character string wherever it occurs. The tricky part is that the target string is not a constant, it is recognized by conforming to a Regular Expression.
This is a contrived example intended to illustrate the question. The actual application has nothing to do with telephone numbers. Some lines in the input file will have no phone numbers.
Insert the character string "Phone:" immediately before any string which looks like a telephone number.
Sample input file ...
Quote:
*------------------
Brickmasons: Herman 914-555-1234
Irving 845-555-2233 James 212-555-4455
*------------------
Carpenters: Larry 518-555-5678 Nathan 718-555-2244
*------------------
|
Desired output file ...
Quote:
*------------------
Brickmasons: Herman Phone:914-555-1234
Irving Phone:845-555-2233 James Phone:212-555-4455
*------------------
Carpenters: Larry Phone:518-555-5678 Nathan Phone:718-555-2244
*------------------
|
Daniel B. Martin
|