Showing posts with label sed awk stream editor search and replace bash. Show all posts
Showing posts with label sed awk stream editor search and replace bash. Show all posts

Saturday, December 12, 2009

Simple uses for Sed

Picking up where we left off on the Awk article

We have the following output from a command.

sed@intro > awk ' { print $2" "$1 } ' test.txt
Phone User
555-555-5553 tom
555-555-5552 larry
555-555-5511 daryl

Problem here is the column titles for Phone and User are not aligned with the output information.

Enter Sed

sed@intro > awk ' { print $2" "$1 } ' test.txt | sed 's/Phone User/Phone........User/g'
Phone.............User
555-555-5553 tom
555-555-5552 larry
555-555-5511 daryl


Sed the stream editor is being used to format the output from awk using a search and replace function globally. sed 's/Pattern to match/ What to replace it with/ g'