Basic text filtering with sed. Very useful when you are manipulating text files.

Posted: August 18, 2014. At: 10:46 PM. This was 3 years ago. Post ID: 7665

This example uses sed to replace the beginning word of a sentence.

Administrator@WIN-EM8GK0ROU41 ~
$ echo "this is a line of text." | sed "s/this/This/gi;"
This is a line of text.

This is a better way to capitalize the first letter of every word in the sentence. I found this tip here.

Administrator@WIN-EM8GK0ROU41 ~
$ echo "this is a line of text." | sed -r 's/\<./\U&/g'
This Is A Line Of Text.

And here is how to only capitalize the first letter in the sentence.

Administrator@WIN-EM8GK0ROU41 ~
$ echo "this is a line of text." | sed "s/^./\u&/"
This is a line of text.

Here is a way to use sed without needing cat. I used this to nicely format a HTML file that had no newlines in it and was a mess when printed to the terminal.

sed "s/>/>\n/gi;" index.html

Here is a related command: this will print your gateway IP address.

curl myip.com 2>/dev/null| grep Client_IP:

This is a way to use sed to make this command look even better.

curl myip.com 2>/dev/null| grep Client_IP: | sed "s/Client_IP:/My IP Address is:/gi;"

No comments have been made. Use this form to start the conversation :)

Leave a Reply