SED - Replacing words in selective lines->> '1,3s/word/relaceword/'

 
-----------------------------------------------------------------------------------------------
Replacing words in selective lines->> '1,3s/word/relaceword/'
A range of lines.
A pattern that matches a specific line.
-----------------------------------------------------------------------------------------------


[prabhucloudxlab@cxln4 prabhu]$ cat > filegrep.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
unix linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
ThIs Is LInux 2000
ThIs Is WIndows 3000
ThIs Is MAC 4000
ThIs Is LInux 2000
ThIs Is WIndows 3000



[prabhucloudxlab@cxln4 ~]$ cat>hello.sh
#! /bin/bash
#Example 4: Limiting the sed lines 
echo "enter filename to substitute using sed"
read fileName
echo "                        "
if [[ -f $fileName ]]
then
echo "#modifying only 6th line"
echo "                        "
sed -e '6s/3000/355555555/' $fileName 
echo "====================================="

echo "#modifying unix word in 1,3 lines"
echo "#It will modify  only 1st unix word, because In 2nd unix, U is capitable... "
echo "                        "
sed -e '1,3s/unix/99999999999999999999999/' $fileName
echo "====================================="

echo "#modifying unix word in 1,3 and windows word in 6,9"
echo "#we are using case-sensitive(i)"
echo "                        "
sed -e '1,3s/unix/99999999999999999999999/i; 6,9s/windows/5555555555555555/i' $fileName
echo "====================================="

    else
    echo "$fileName doesn't exist"
fi




[prabhucloudxlab@cxln4 ~]$ sh hello.sh
enter filename to substitute using sed
filegrep.txt

#modifying only 6th line

unix is great os. unix is opensource. unix is free os.
learn operating system.
Unix linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
ThIs Is LInux 2000
ThIs Is WIndows 355555555
ThIs Is MAC 4000
ThIs Is LInux 2000
ThIs Is WIndows 3000
=====================================
#modifying unix word in 1,3 lines
#It will modify  only 1st unix word, because In 2nd unix, U is capitable...
99999999999999999999999 is great os. unix is opensource. unix is free os.
learn operating system.
Unix linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
ThIs Is LInux 2000
ThIs Is WIndows 3000
ThIs Is MAC 4000
ThIs Is LInux 2000
ThIs Is WIndows 3000
=====================================
#modifying unix word in 1,3 and windows word in 6,9
#we are using case-sensitive(i)
99999999999999999999999 is great os. unix is opensource. unix is free os.
learn operating system.
99999999999999999999999 linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
ThIs Is LInux 2000
ThIs Is 5555555555555555 3000
ThIs Is MAC 4000
ThIs Is LInux 2000
ThIs Is 5555555555555555 3000
=====================================