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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change all occurences of a character

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
hi!

how to change occurences of one character in a file to another character?

example, replace all ";" sign with "=" sign???

thank you!
sinya
 
This will change all occurrences - remove the 'g' to change just the first one on each line.

sed 's/;/=/g' < textfile

Chris

 
In the case of needing to replace most but not all of the occurances.

Add a c to the end of the command that Chris provided

sed 's/;/=/gc' <text file>


The c is the option for confirm so you will be prompted for each change.
 
Also:
Code:
tr ';' '='

For more info:
Code:
man tr
 
WHAT IF YOU WANTED TO WRITE THE OUTPUT TO ANOTHER FILE INSTEAD OF STANDART OUTPUT? AND STILL KEEP THE ORIGINAL FILE INTACT.
DO I JUST ADD THE > FILENAME AFTER THE SED COMMAND
THANKS
5SORRY ABOUT THE CAPS? MY CAPS KEY IS STUCK)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top