Text ManipulationOr not so common...
Note: Brackets [ ] indicate that you need to change those places with appropriate substitutions. Typically there shouldn't be any brackets in the command.
Command Name: sedDescription:This command replaces stings in a text file. Replace the first instance of a string in each line of a file:
sed -i 's/[ToBeReplaced]/[Replacing]/' [TextFile]
Example:
sed -i 's/me/you/' text.txt
Replace every instance of a string in a file:
sed -i 's/[ToBeReplaced]/[Replacing]/g' [TextFile]
Example:
sed -i 's/me/you/g' text.txt
NOTE: If using this command on a Mac box there needs to be an extention added to the '-i' parameter as it requires it to create a backup of the file before it will edit it in-place.
sed -i [extention] 's/[ToBeReplaced]/[Replacing]/g' [TextFile]
Example:
sed -i .bk 's/me/you/g' text.txt
This will create a backup file named 'text.txt.bk' and then edit 'text.txt' in-place | ||
