Shell Practice: Introduction to the sed stream editor

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Shell Variables

If a shell variable needs to be resolved, you need to enclose the statements in double quotes (" ) instead of single quotes (' ). The little shell script in Listing 3 shows how to handle variables. It searches through the sample file and outputs the matching lines. Figure 22 shows the result.

Listing 3

01 #! /bin/sh
02 echo -n "Enter search string: ";read sstring
03 cat textdata.txt | sed -n "/$sstring/"p
Figure 22: Handling variables in Bash scripts.


With sed, you can execute complex text manipulation without user intervention. Its cryptic syntax might seem cumbersome at first, which is why building scripts bit by bit is a great option.


  1. Project page for sed:

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content