Construct pipes to execute the following jobs?

1. Output of who should be displayed on the screen with value of total number of users who have logged in displayed at the bottom of the list.2. Output of ls should be displayed on the screen and from this output the lines containing the word ‘poem’ should be counted and the count should be stored in a file. 3. Contents of file1 and file2 should be displayed on the screen and this output should be appended in a file .From output of ls the lines containing ‘poem’ should be displayed on the screen along with the count.4. Name of cities should be accepted from the keyboard . This list should be combined with the list present in a file. This combined list should be sorted and the sorted list should be stored in a file ‘newcity’.5. All files present in a directory dir1 should be deleted any error while deleting should be stored in a file ‘errorlog’.

Showing Answers 1 - 10 of 10 Answers

gangolli

  • Oct 18th, 2005
 

who | echo "total users `who|wc -l`"ls | grep -c "poem" | tee filename.txtcat file1 file2 >> filetoappendto.txt??rm -rf dir1 | tee errorlog

  Was this answer useful?  Yes

madhu

  • May 23rd, 2006
 

1)       who & echo ?Total number of users are ` who | wc ?l` ?

muru

  • Nov 21st, 2006
 

1. who | tee /dev/pts/4 | cut -d " " -f 1 | uniq | echo "no of users logged in are `wc -l`" who - displays all the loged in users tee - pass the who output to terminal output /dev/pts/4 and also to cut command. where /dev/pts/4 is the current terminal. use tty to get your current terminal cut -d " " -f 1 will cut the first field of who o/p which is login name uniq command is used to merge duplicate logins to single entry. This might be in some cases a single user might have logged in from different terminals and in such case they should not be counted as separate users. wc -l give total number of line which is here is the total users logged in. eg o/p: root pts/3 Nov 14 14:30 root pts/4 Nov 21 12:25 no of users logged in are 12. ls | tee /dev/pts/4 | grep -c "poem" > count | cat count3. sort -m fil1 file2 | tee /dev/pts/4 | sort -o outputfile 4. sort - file1 -o newcity enter extra string from keyboard and press Ctrl+d key combination to finish the input5. rm -rf /dir 2>errorlog where 2 denotes "standard error" which is here redirected to errorlog file instead of user terminal

  Was this answer useful?  Yes

Phany123

  • Mar 1st, 2011
 

cat file1 && cat file2 && cat file1 file

who && echo "number of users are `who | wc -l`"


#!/usr/bin/ksh
for file in *
do
echo $file >> filex
echo `cat $file | grep "poem" -c` >> filex
done  

#!/usr/bin/ksh
touch filex
echo "please enter city"
while read city
do
echo $city>>filex
done
echo "n n the contents of both files sorted are"
cat filex filey | sort
cat filex filey | sort>> newcity
rm filex

  Was this answer useful?  Yes

ram

  • Aug 30th, 2011
 

For 2)
ls | tee Output_of_ls.txt && grep -c "poem" Output_of_ls.txt > Output_of_count.txt

  Was this answer useful?  Yes

kiran

  • Dec 14th, 2011
 

Ans for question 1

echo `who`\n the number of users logged in is `who | wc -l`

  Was this answer useful?  Yes

santosh

  • Mar 20th, 2012
 

who;echo "Total number of users: "`who|wc -l`

  Was this answer useful?  Yes

praveen

  • Apr 11th, 2014
 

1. Output of who should be displayed on the screen with value of total number of users who have logged in displayed at the bottom of the list.

Ans: who | tee users.txt && who | wc -l

2. Output of ls should be displayed on the screen and from this output the lines containing the word poem should be counted and the count should be stored in a file.

Ans: ls poem | tee a.txt && grep -c poem a.txt > b.txt


3. Contents of file1 and file2 should be displayed on the screen and this output should be aCppended in a file .From output of ls the lines containing poem should be displayed on the screen along with the count.

Ans : cat file1 file2 | tee file3


From output of ls the lines containing ‘poem’ should be displayed on the screen along with the count.

Ans: ls -l poem | tee a.txt && grep -c poem a.txt | tee b.txt

4. Name of cities should be accepted from the keyboard . This list should be combined with the list present in a file. This combined list should be sorted and the sorted list should be stored in a file newcity.

Ans : echo "Please enter the city" read -a fname && tee a.txt >> city && sort city > newcity

5. All files present in a directory dir1 should be deleted any error while deleting should be stored in a file errorlog.

Ans : rm -i praveen 2> errorlog

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions