Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed - (inserting text)

Status
Not open for further replies.

richy00

MIS
Nov 13, 2000
21
US
I am currently writing a shell (korn) script that automates a number of different tasks. One task in particular is giving me a little bit of trouble. I am trying to insert a text string at the beginning of each line in a text file using sed. Unfortunately, sed deletes the line when the insert is made, thus removing any existing text on each line. Does anyone know how to insert or (pre-pend) a text string to the beginning of each line in a file, while not affecting the text that’s already there?

Example:

-Before-
Smith, John
White, Bob
Jones, Frank

-After-
<option>Smith, John
<option>White, Bob
<option>Jones, Frank

As shown in the example, I want to insert the text string “<option>” before each existing line(s) that contain text, without removing the existing text.
 
try sed -e 's/^/text to input/g'

Tony ... aka chgwhat
tony_b@technologist.com

When in doubt,,, Power out...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top