OPERATING SYSTEMS Lab Assignment-01
Submitted By: AKHIL SINGH, Enrolment No.: IIT2018198, B. Tech IT 3rd Semester, Section: ‘B’
1. $ who > myfile1 | more myfile1
2. $ date; who > myfile2
$ more myfile2
3. $ sed 's/\([^ ]*\) *\ ([^ ]*\)/\2\1 /g' [Link]
4. write command echo "Hello World" and save as [Link] file.
Write following in another file
#include<stdio.h>
int main ()
printf("Hello World\n");
Save as hello.c
On terminal run the following commands :
$ chmod +x [Link]
$ time ./[Link]
$ run gcc hello.c -o hello
$ time ./hello
5.
echo "Enter Filename :"
read filename
if test-f $filename
then echo “__Ordinary_File__"
elif test-d $filename
then echo "__Directory_File__"
else
echo "__File_does_not_exist__"
fi
6.
echo -n "Enter File Name : "
read filename
if [ ! -f $filename ]
then
echo "Filename $filename does not exists"
exit 1
fi
tr '[A-Z]' '[a-z]' < $fileName
7. echo "Enter the USER NAME : "
read user
last $user
run chmod +x [Link]
./[Link]
8.
echo "Enter the Document name :"
read docname
echo "Enter the starting line number"
read startline
echo "Enter the ending line number"
read endline
sed -n $startline,$endline\p $docname | cat > newline
cat newline
9.
#!/bin/bash
if [ $# -lt 2 ]
then
echo "Not enough arguments …Supply word then at least one file….."
exit 1
fi
search_word=$1
for file_name in "$@"
do
if [ "$file_name" = "$1" ]
then
continue
fi
echo $file_name
echo "--------------------"
if [ ! -f $file_name ]
then
echo "File \"$file_name\" does not exist"
exit 2
fi
while read line
do
if ( ! ( echo $line | grep "$search_word" > /dev/null ) )
then
echo $line
fi
done < $file_name
done
10.
echo "Enter a String : "
read STRING
echo "Enter start index of Sub-String : "
read STRTPOS
echo "Enter length of Sub-string : "
read STRL
echo ${STRING:$STRTPOS:$STRL}