Deep 54 Unix
Deep 54 Unix
Deep 54 Unix
ASSIGNMENT : 1
who :- tells you who's logged on, and where they're coming from. Useful
if you're looking for someone who's actually physically in the same
building as you, or in some other particular location.
kill PID --- kills (ends) the processes with the ID you gave. This works
only for your own processes.
tee :- tee command reads the standard input and writes it to both the
standard output and one or more files.
more filename :- shows the first part of a file, just as much as will fit on
one screen. Just hit the space bar to see more or q to quit.
sort ---rearranges the lines in a text file so that they are sorted,
numerically and alphabetically.
-b,
--ignore-leading- Ignore leading blanks.
blanks
-d, --dictionary-order Consider only blanks and alphanumeric characters.
-f, --ignore-case Fold lower case to upper case characters.
-g,
--general-numeric- Compare according to general numerical value.
sort
-i, --ignore-
Consider only printable characters.
nonprinting
-M, --month-sort Compare (unknown) < `JAN' < ... < `DEC'.
-h,
Compare human readable numbers (e.g., "2K", "1G").
--human-numeric-sort
-n, --numeric-sort Compare according to string numerical value.
-R, --random-sort Sort by random hash of keys.
date ---used to print out, or change the value of, the system's time and
date information.
-d, --
Reuse characters from LIST instead of tabs.
delimiters=LIST
-s, --serial Paste one file at a time instead of in parallel.
--help Display a help message, and exit.
-c, --count Prefix lines with a number representing how many times they occurred.
uniq ---filters out adjacent, matching lines from input file INPUT, writing
the filtered data to output file OUTPUT.
gerp ---stands for "global regular expression print." It is a powerful tool for
matching a regular expression against text in a file, multiple files, or a
stream of input. It searches for the PATTERN of text you specified on the command
line, and outputs the results for you.
-e PATTERN, Use PATTERN as the pattern to match. This can specify multiple search
--regexp=PATTERN patterns, or to protect a pattern beginning with a dash (-).
-f FILE, --file=FILE Obtain patterns from FILE, one per line.
-i, --ignore-case Ignore case distinctions in both the PATTERN and the input files.
-v, --invert-match Invert the sense of matching, to select non-matching lines.
Select only those lines containing matches that form whole words. The
test is that the matching substring must either be at the beginning of the
line, or preceded by a non-word constituent character. Or, it must be
-w, --word-regexp
either at the end of the line or followed by a non-word constituent
character. Word-constituent characters are letters, digits, and
underscores.
-x, --line-regexp Select only matches that exactly match the whole line.
-y The same as -i.
sed --- The sed stream editor performs basic text transformations on an input
stream.
Assignment 2
Write a command to display “Hello friend, (current date in DD-MM-
YYYY) TODAY is (current date in DD-MM-YYYY) Good Day”
1. today=$(date +'%d/%m/%Y')
2. echo "Hello Friend, Today is ${today}. Good day!"
Write a shell script to find smallest of three numbers that are read from
keyboard.
1. for i in {1..10}
2. do
3. echo "Text ${i}" >> "file.txt"
4. done
Write a shell script to count the total number of words and lines of the
given file.
Write a shell script to check whether the given file is empty or not.
1.echo "Ente
2. w=`wc --word < $fname`
3. if [ ${w} -eq 0 ];
4. then
5. echo "$fname is empty."
6. else
7. echo "$fname is not empty."
8. fi
9. r a Filename:"
10. read fname
1.mycal(){
2.re='^[0-9]+$'
3.if [ $# -ne 3 ]
4.then
echo "All parameters not inputed. Please provide a space
b/w parameters."
5. else
ans=`expr $1 $2 $3`
echo "Result: $ans"
6. fi
7.}
mycal 1 + 2
Write a shell script to accept n numbers and tell how many are positive,
negative and zero. Also display all numbers in ascending order.
5. while [ $i -lt $n ]
6. do
7. read a[$i]
8. i=`expr $i + 1`
9. done
23. arr=(0 0 0)
24. i=0
25. while [ $i -lt $n ]
26. do
27. if [ a[$i] -eq 0 ]
28. then
29. arr[0]=`expr ${arr[0]} + 1`
30. elif [ a[$i] -gt 0 ]
31. then
32. arr[1]=`expr ${arr[1]} + 1`
33. else
34. arr[2]=`expr ${arr[2]} + 1`
35. fi
36. i=`expr $i + 1`
37. done
Assignment 3
Write command for following:
cat -n student.txt
sed -n ’10,15 p ‘ f1
4. To display total number of words and lines of files for which filename
starts with 'm'.
rmdir dir3/dir2/dir1
6. To remove all files that begins with digit from the parent directory to
current directory.
chmodugo=rw f1
chmodugo=x f2
11.Write a command using grep or sed or awk to display all lines that
contains 'ab*' in a line.
grep “ab*” f1
13.Write a command using grep or sed or awk to locate lines that begins and
end with .(dot)
sed -n "/^\./p"
15.Write a command using grep or sed or awk to replace 'hello' with 'Good
Morning' in input file 'a1.sh' and write those lines to output file 'a2.sh'