Problem1 : Write a script in shell or in python , which is able to store 50 commands which you have previous entered through terminal and execute each command .
Problem 2: Execute the program that will read the file content and print those content adding with line number and arranged in the alphabetical order
Problem 3: Read a file of 20 lines , information then print with line number and another file print only word list with their frequency of occurance and character counts in each word as another description of the word into the third file .
=========
Solutions
=========
Solution 1: Shell script
Step 1:Open terminal type Step 2 Code .
Step 2: ( We assume you have typed 50 commands through terminal )
fc -ln -50 > abc.sh
Description : The fc command is a command line utility for listing, editing and re-executing commands previously entered into an interactive shell.
Above command will save 50 previous commands into abc.sh
Step 3: chmod +x abc.sh
//give execute permission
Step 4: ./abc.sh
//execute command
Solution 2 : Please visit below url for file operation in Python
https://www.digitalocean.com/community/tutorials/how-to-handle-plain-text-files-in-python-3#step-1-%E2%80%94-creating-a-text-file
https://stackoverflow.com/questions/19001402/how-to-count-the-total-number-of-lines-in-a-text-file-using-python
https://www.programiz.com/python-programming/examples/alphabetical-order
#open file
days_file = open("hem.txt",'r')
num_lines = sum(1 for line in open('hem.txt'))
#print(num_lines)
count=1
#make a list of item
lines=list(days_file)
for lin in lines:
String=sorted(lin.split(), key=str.lower)
str1 = ' '.join(String)
print(count,str1)
count=count+1
days_file.close();
Solution 3:
Please go below link for more
https://www.pitt.edu/~naraehan/python2/split_join.html
https://developers.google.com/edu/python/strings
from collections import Counter
#open the file
filepath =open('xyz.txt')
#code 1
#store all file in lines
lines=filepath.readlines()
list=[]
#call till 20 values
for i in range(20):
#retrieve each line
String=lines[i]
print(i+1,":",String)
#split each word
words = String.split()
list.extend(words)
#print(words)
#print(list)
c=Counter(list)
c.values()
print("Word Frequency Count")
for key,value in c.items():
string=key
print(key,value,len(string)-string.count(' '))
3 Files in a zip .
I have used python 2.7+ .
https://drive.google.com/file/d/1Nn_K7hzge5nIhWX32xNeDNklo53CVsln/view?usp=sharing
No comments:
Post a Comment