SED All Commands

 [prabhucloudxlab@cxln4 ~]$ 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 linux 2000
ThIs is WIndows 3000


[prabhucloudxlab@cxln4 ~]$ cat>sedcommands_file
s/LInux/HARI_TARAKA_PRABHU/;
s/WIndows/MANYAM_MANYAM/;


#SCRIPT
#! /bin/bash
#shell commands
echo "enter filename to substitute using sed"
read fileName
echo "                                         "
if [[ -f $fileName ]]
then
echo "#replacement of letters"
echo "                                         "
    cat $fileName | sed 's/i/I/'
echo "==============================================================="

echo "#global replacement letters"
echo "                                         "
cat $fileName | sed 's/i/I/g'
echo "==============================================================="
echo "#global replacement words"
echo "                                         "
cat $fileName | sed 's/linux/Unix/g'
echo "==============================================================="

echo "#case sensitive"
echo "                                         "
cat $fileName | sed 's/linux/Unix_Unix_Unix/gi'
echo "==============================================================="

echo "#multiple sed commands"
echo "                                         "
cat $fileName | sed -e 's/3000/3555555/; s/ThIs Is/ITS a/'
echo "==============================================================="

echo "#removing lines"
echo "                                         "
cat $fileName | sed -e '/WIndows/d; /unix/d '
echo "==============================================================="

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

echo "#Translate"
echo "                        "
cat $fileName | sed 'y/abcfghijklmn/1234567890XY/'
echo "==============================================================="


echo "READING LINES"
echo "                                        "

echo "#reading 1st line"
cat $fileName | sed -n '1p'
echo "              "

echo "#reading lines from 1 to 4"
cat $fileName | sed -n '1,4p'
echo "              "

echo "#reading lines 3, 7"
cat $fileName | sed -ne '3p' -ne '7p'
echo "              "
echo "==============================================================="


echo "#Printing lines that contain a particular word"
echo "                        "
cat $fileName | sed -n '/WIndows/p'
echo "==============================================================="


echo "Replacing selective occurrence"
echo "                        "
echo "#4th occurrence of all lines"
echo "                        "
cat $fileName | sed 's/unix/25555555555555555555/4i'
echo "==============================================================="

echo "#After remove blank records"
echo "                        "
cat $fileName | awk -F " " '{print $4}' | sed '/^$/d'
echo "==============================================================="



echo "#reading commands from another SED commands fileName"
echo "                        "
cat $fileName | sed -f sedcommands_file
echo "==============================================================="

else
    echo "$fileName doesn't exist"
fi



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

#replacement of letters
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 linux 2000
ThIs Is WIndows 3000
===============================================================
#global replacement letters

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 lInux 2000
ThIs Is WIndows 3000
===============================================================
#global replacement words

unix is great os. unix is opensource. unix is free os.
learn operating system.
Unix Unix 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 Unix 2000
ThIs is WIndows 3000
===============================================================
#case sensitive

unix is great os. unix is opensource. unix is free os.
learn operating system.
Unix Unix_Unix_Unix which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
This Is Unix_Unix_Unix 2000
ThIs is Windows 3000
This Is Unix_Unix_Unix 2000
ThIs is WIndows 3000
===============================================================
#multiple sed commands

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 3555555
This Is linux 2000
ThIs is WIndows 3555555
===============================================================
#removing lines

learn operating system.
Unix linux which one you choose.
This Is Linux 2000
ThIs is Windows 3000
This Is linux 2000
===============================================================
#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 linux 2000
ThIs is 5555555555555555 3000
===============================================================
#Translate

uY7x 7s 5re1t os. uY7x 7s opeYsour3e. uY7x 7s 4ree os.
0e1rY oper1t7Y5 systeX.
UY7x 07Yux w6736 oYe you 36oose.
uN7x 7s e1sy to 0e1rY.uY7x 7s 1 Xu0t7user os.Le1rY uY7x .uY7x 7s 1 power4u0.
T67s Is L7Yux 2000
T6Is 7s W7Ydows 3000
T67s Is 07Yux 2000
T6Is 7s WIYdows 3000
===============================================================
READING LINES

#reading 1st line

unix is great os. unix is opensource. unix is free os.

#reading lines from 1 to 4
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.

#reading lines 3, 7
Unix linux which one you choose.
This Is linux 2000
===============================================================
#Printing lines that contain a particular word

ThIs is WIndows 3000
===============================================================
Replacing selective occurrence
#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 linux 2000
ThIs is WIndows 3000
===============================================================
#After remove blank records
os.
one
to
2000
3000
2000
3000
===============================================================
#reading commands from another SED commands fileName
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 linux 2000
ThIs is MANYAM_MANYAM 3000
===============================================================