SED - Replacing selective occurrence (sed 's/unix/25555/4i' $fileName )

 
=========================================================================
Replacing selective occurrence
=========================================================================
[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
#Replacing selective occurrence 

echo "enter filename to substitute using sed"
read fileName
echo "                        "

if [[ -f $fileName ]]
then
echo "#4th occurrence of all lines"
echo "                        "
sed 's/unix/25555555555555555555/4i' $fileName 
echo "====================================="

echo "#2nd occurrence of all lines"
echo "                        "
sed 's/unix/25555555555555555555/2i' $fileName 
echo "====================================="

echo "#1st occurrence of all lines"
echo "                        "
sed 's/2000/9999999999999999999/1i' $fileName 
echo "====================================="

    else
    echo "$fileName doesn't exist"
fi




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

#4th occurrence of all lines
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 .25555555555555555555 is a powerful.
ThIs Is LInux 2000
ThIs Is WIndows 3000
ThIs Is MAC 4000
ThIs Is LInux 2000
ThIs Is WIndows 3000
=====================================
#2nd occurrence of all lines
unix is great os. 25555555555555555555 is opensource. unix is free os.
learn operating system.
Unix linux which one you choose.
uNix is easy to learn.25555555555555555555 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
=====================================
#1st occurrence of all lines
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 9999999999999999999
ThIs Is WIndows 3000
ThIs Is MAC 4000
ThIs Is LInux 9999999999999999999
ThIs Is WIndows 3000
=====================================