shell script that deletes all lines containing given word

Script:
#deletes all lines containing a specific word in one or more files supplies via #arguments
if [ $# -eq 0 ]
    then
        echo No arguments
else
    pattern=$1
    shift #used when supplied arguments for loops as to not alter arguments
    for fname in $*
        do
            if [ -f $fname ]
                then
                    echo Deleting $pattern from $fname
                    sed -e ' /'$pattern'/d ' $fname
            else
                echo $fname not found
            fi
        done
fi

Output:
root@root:~/os# sh 2b.sh this test1 test2
Deleting this from test1
line 9 has santosh in test1 file
at line 10 im done  in test1 file
Deleting this from test2
line 9 has santosh in test2 file
at line 10 im done  in test2 file

 

Comments

Popular posts from this blog

Multi-programming with variable number of tasks(MVT) program in C

Multi-programming with fixed number of tasks(MFT) program in C

Linked file allocation program in C.