Usp

 5. Write awk script that uses all of its features.


#!/bin/awk -f

BEGIN {print “START”}

{print $1, “\t”, $3}

END {print “DONE”}

output:

 [LabExam@ISELAB1 ~]$ awk -f pr5.awk a.txt

And am

You can

Me you

LabExam@ISELAB1 ~]$ cat a.txt

And is am I was

You they can take

Me as you print



6. Write a shell script to display list of users currently logged in.


#!/bin/sh

echo “User logged in:”

users

echo “Current logged in date and time :”

date

echo “Currently logged in users:”

who

echo “Currently logged in username:”

whoami

output:

 [LabExam@ISELAB1 ~]$ sh pr6.sh

[LabExam@ISELAB1 ~]$chmod a+x pr6.sh

[LabExam@ISELAB1 ~]$sh pr6.sh

User logged in:

UNIX LAB UNIX LAB

Current logged in date and time:

Sat sep 29 12:25:30 IST 2018-11-22

Currently logged in users:

UNIXLAB TTY1 2018-09-29 11.08 (:0)

UNIXLAB pts/0 2018-09-29 12.03 (:0.0)

UNIXLAB pts/1 2018-09-29 12.28 (:0.0)

Currently logged in username:

UNIXLAB



PART B


1. Write a C/C++ program to implement the cat command using general file API’s.


#include<sys/types.h>

#include<sys/stat.h>

#include<stdio.h>

#include<fcntl.h>

main( int argc,char *argv[3] )

{

int fd,i;

char buf[2];

fd=open(argv[1],O_RDONLY,0777);

if(fd==-argc)

{

printf("file open error");

}

else

{

while((i=read(fd,buf,1))>0)

{

printf("%c",buf[0]);

}

close(fd);

}

}

Output: [UNIXLAB@localhost ~]$ gcc -0 p.out prgm1.c

UNIXLAB@localhost ~]$cat >h.txt /*creating a text file*/

hello

UNIXLAB@localhost ~]$./p.out h.txt /*appending text file to display contents on the terminal without using cat command*/

hello

Comments

Popular posts from this blog

final

data science