0% found this document useful (0 votes)
1K views

Write A Shell Script To Create A File in

This shell script performs the following tasks: 1. It creates a file in the $USER/class/batch directory and copies the contents of one file to another existing file. 2. It starts printing the contents of a file from a certain line number. 3. It prints the differences between two files, copies the files to the $USER/CSC/2007 directory, and outputs the differences to a third file. 4. It prints lines from a file that match a certain word pattern.

Uploaded by

waa_qureshi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Write A Shell Script To Create A File in

This shell script performs the following tasks: 1. It creates a file in the $USER/class/batch directory and copies the contents of one file to another existing file. 2. It starts printing the contents of a file from a certain line number. 3. It prints the differences between two files, copies the files to the $USER/CSC/2007 directory, and outputs the differences to a third file. 4. It prints lines from a file that match a certain word pattern.

Uploaded by

waa_qureshi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

.

Write a shell script to create a file in $USER


/class/batch directory. Follow the
Instructions
(i) Input a page profile to yourself, copy it into
other existing file;
Solution:- #vim assignment4.1.sh
echo”create a file in /user/class/batch in
directory”
mkdir –p user/class/b1
echo “Display present working DIR”
cd user/class/b1
pwd
echo “Enter a file name”
read file1
echo “Enter contains in $file1”
cat > $file1
echo “Enter existing file name”
read file2
echo “Display copy of contains $file1 to $file2”
cp $file1 $file2
cat $file2
(ii) Start printing file at certain line
Solution:- #vim assignment4.2.sh
echo”create a file in /user/class/batch in
directory”
mkdir –p user/class/b1
echo “Display present working DIR”
cd user/class/b1
pwd
(iii) echo “Enter a file name”
read file1
echo “Enter contains in $file1”
cat > $file1
echo “Start Printing at 5 line “
tail +5 $file1

(iii) Print all the difference between two file, copy


the two files at
$USER/CSC/2007 directory.
Solution:- #vim assignmentno4.3.sh
echo “enter first file name”
read file1
echo “enter second file name”
read file2
echo “enter third file name”
read file3
echo “Enter contains to $file1”
cat > $ file1
echo “Enter contains to $file2”
cat > $ file2
echo “Display difference between $file1 and $file2
copy to $file3”
diff –a $file1 $file2 > $file3
cat $file3

iv )Print lines matching certain word pattern.


Solution :-
#mkdir IT
#cd IT
#vim assignmentno4.4.sh
echo “create a file “
read file1
echo “inputs contains in file $file1”
cat > $file1
echo “Enter word we findout “
read f
grep –ni $f $file1
Assignment No:-5

5.Write shell script for-


(i) Showing the count of users logged in,
sol-> echo “ Show all users login”
who
echo “ count all login name”
who |wc -l
(ii)Printing Column list of files in your home
directory
sol -> echo “ Printing 3-colomn in a Home
directory”
ls – l | cut -17-24,39 - 42,56 -

(iv) Listing your job with below normal priority


Sol-> echo “list of normal priority “
ps – al
echo – al | cut – c26-29, 70 -

(v) Continue running your job after logging


out.
# nohup command-with-options
&
note:- Nohup stands for no
hang up

Assignment No:-6
6. Write a shell script to change data format. Show
the time taken in execution of
this script.
echo “ Enter file name “
read fname
echo “ Input contains in $fname”
cat > fname
echo “Display create file than current time “
ls –l $fname
echo “ Modification $fname”
vi $ fname
echo “ show access time “
ls –ult $fname
echo “ show modification time “
ls –clt $ fname
Output

Assignment No:-7
7. Write a shell script to print files names in a
directory showing date of creation
& serial number of the file.
echo “sort login name by time”
echo “show login name”
who
echo “show only name and time “
who | gwk ‘{print $1,$5}’
echo “show sort by time “
who |gawk ‘{ print $5,$1}’
Output
Show only name and time
root 12:48
show sort by time
12:48 root
………………………………………………………
…………………
Assignment No:-8
8. Write a shell script to count lines, words and
characters in its input (do not use
wc).
read –p “create file name “
fname
echo “input the contains of file “
cat > $ fname
clear
echo “ Display all record “
cat $fname
echo “ show file line , word ,char”
gawk ‘{ nc+=length ($0)+1nw +=NF}
END ‘{print “ line =” NF , “\n word =”nw, “\n char
=”nc}’ $fname
Output
Create and enter file name
Display all records
11
22
33

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy