[prabhu@cxln4 ~]$ cat>filegrep.txt
Name Email Phone
Jonathon Bing - 1001 jon@gmail.com 01967456323
Micheal Jackson - 2006 mic@gmail.com 01756235643
Janifer Lopez - 3029 jani@gmail.com 01822347865
John Abraham - 4235 john@gmail.com 01590078452
Mir Sabbir - 2756 mir@gmail.com 01189523978
#! bin/bash
#Printing Columns
Name Email Phone
Jonathon Bing - 1001 jon@gmail.com 01967456323
Micheal Jackson - 2006 mic@gmail.com 01756235643
Janifer Lopez - 3029 jani@gmail.com 01822347865
John Abraham - 4235 john@gmail.com 01590078452
Mir Sabbir - 2756 mir@gmail.com 01189523978
#! bin/bash
#Printing Columns
echo "enter a filename to print from awk"
read fileName
if [[ -f $fileName ]]
then
echo " Printing 1st column in given text file"
cat $fileName | awk ' { print $1 } '
echo "================================================================"
echo " Printing 1st column with delimeter given text file"
cat $fileName | awk -F '-' ' { print $1 } '
echo "================================================================"
echo " Printing last column in given text file"
cat $fileName | awk ' { print $NF } '
echo "================================================================"
echo " Printing 1st line & last column in given text file"
cat $fileName | awk ' { print $1,$NF } '
echo "================================================================"
echo " Printing 1st row 3rd column"
cat $fileName | awk 'NR==1 {print $3}'
echo "================================================================"
echo " Printing 1st row 3rd column and 3rd row 2nd column"
cat $fileName | awk 'NR==1 {print $3} NR==3 {print $2}'
echo "================================================================"
echo " Printing 4th row 1st column and 3rd row 4th column"
cat $fileName | awk 'NR==4 {print $1} NR==3 {print $4}'
echo "================================================================"
else
echo "$fileName doesn't exist"
fi
[prabhu@cxln4 ~]$ sh hello.sh
enter a filename to print from awk
filegrep.txt
Printing 1st column in given text file
Name
Jonathon
Micheal
Janifer
John
Mir
================================================================
Printing 1st column with delimeter given text file
Name Email Phone
Jonathon Bing
Micheal Jackson
Janifer Lopez
John Abraham
Mir Sabbir
================================================================
Printing last column in given text file
Phone
01967456323
01756235643
01822347865
01590078452
01189523978
================================================================
Printing 1st line & last column in given text file
Name Phone
Jonathon 01967456323
Micheal 01756235643
Janifer 01822347865
John 01590078452
Mir 01189523978
================================================================
Printing 1st row 3rd column
Phone
================================================================
Printing 1st row 3rd column and 3rd row 2nd column
Phone
Bing
================================================================
Printing 4th row 1st column and 3rd row 4th column
1001
Micheal
================================================================