Write a program called mysed that applies the sed script given as the first argument against the file given as the second. If the sed succeeds (that is, exit status of zero), replace the original file with the modified one. Thus:
mysed '1,10d' text
will use sed to delete the first 10 lines from text, and, if successful, will replace text with the modified file
A script like this needs some tests to ensure that the user isn't going to break anything, so this is more complex, as is appropriate for the task. It also uses a variable called tempfile to store the contents of the sed invocation temporarily.
tempfile="mysed.temp"
if [ $# -ne 2 ] ; then
echo "Usage: mysed SEDARG filename" ; exit 1
fi
if [ ! -r "$2" ] ; then
echo "File $2 not found or not readable." ; exit 2
fi
sed "$1" $2 > $tempfile
if [ $? -eq 0 ] ; then
mv $tempfile "$2"
else
rm $tempfile
echo "file contents not updated due to sed failure"
fi
You might also like to view...
Write a C++ code fragment that is assumed to be embedded in an otherwise complete and correct program. You are to assume the user has been prompted (so you don’t have to) for (exactly) 20 values of type int to be read from the keyboard, You are to use this input to fill an array. Do not write a full program, just the code fragment to do this. Do give declarations of the array and any variables you use.
What will be an ideal response?
Flash files that you create are known as ____.
A. animations B. documents C. sheets D. flicks
How are arrays stored in memory locations?
A. randomly B. in parallel C. contiguously D. vertically
To protect your wireless network, it is a good idea to change the router's default ________
Fill in the blank(s) with correct word