unix grep command
Definition : Write a script that deletes all leading and trailing spaces in all lines in a file. Also remove blank lines from a file. Locate lines containing only printf but not fprintf
File Name : ex27.sh
clear
echo "Enter file name : "
read fileName
if [ -f $fileName ]
then
echo "____________________________________"
echo " Trim File .... "
echo "____________________________________"
# Delete leading & trailing whitespace from each line and store it tempFile.txt
sed 's/^[ \t]*//;s/[ \t]*$//;' $fileName >tempFile.txt
# Remove all blank lines from tempFile.txt
sed '/^$/d' tempFile.txt
# Replace content of this two file
mv tempFile.txt $fileName
else
echo "File Not Found"
fi
echo "____________________________________"
echo " Located Lines .... "
echo "____________________________________"
# Locate lines containing only printf but not fprintf
grep -e "printf" $fileName | grep -v "fprint"
Write a script to learn command line argument
Definition : Write a script that behaves both in interactive and non-interactive mode. When no arguments are supplied, it picks up each C program from current directory and lists the first 10 lines. It then prompts for deletion of the file. If the user supplies arguments with the script, then it works on those files only.
File Name : ex26.sh
flag=1
if
[ $# -ne 0 ]
then
# if user provide arguments
echo $* >temp
flag=1
else
# if user not provide arguments
ans=`ls *.c`
if [ "" ==
"$ans" ]
then
echo "There are no
c file"
flag=0
else
ls *.c>temp
flag=1
fi
fi
if
[ $flag -eq 1 ]
then
for filename in `cat temp`
do
if [ -f $filename ]
then
echo "_______________
$filename _______________"
sed -n -e
"1,10 p" $filename
rm -i
$filename
fi
done
rm
temp
fi
Write a script to display the last modified file
File Name : ex24.sh
clear
echo
"Enter Directory Name :\c"
read
dir1
cd
$dir1
ls
-lt | head -2 | tail -1 |cut -d " " -f 10
Write a script to display all lines of a file in ascending order
File Name : ex23.sh
clear
echo
"Enter File Name :\c"
read
filename
sort
$filename
Write a script to display all words of a file in ascending order.
File Name : ex22.sh
echo
"Enter File name:\c"
read
fn
for i in `cat $fn`
do
echo
$i >> f2.txt
done
sort
f2.txt
rm
f2.txt
Subscribe to:
Posts (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- CSS (3)
- Configure Tomcat7 (2)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- WTAD (34)
- c (11)
- install Tomcat (2)
- linux (8)
- shell script (33)
- unix (22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.