F3 Code

 

1.HIGH SCORE

 

cut -d '|' -f 2,5 tmp/prog.txt | sort -t '|' -k2,2nr | awk '{print $1$2}' | head -n 3

 

output:

AlexaAndrews

FionaFerguson

EddieEricsson

-----------------------------------------------------------------------------------------------------------------------------------

2.LINE NUMBERS

 

read -p "Enter the word" word

result=$(grep -ni "$word" introduction.txt)

echo $result

 

output:

Enter the word :Alarum

1:I introduce to you, Alarum 4: This is where I find Alarum

--------------------------------------------------------------------------------------------------------------------------------------

3.’THE’ CODE

 

grep -i  “the”  filename.txt

                  (or)

Filename =” “

grep -i “the” $filename.txt

output:

-i   =====è   it is case insensitive

---------------------------------------------------------------------------------------------------------

4. I WAS WRONG

 

count=$(grep -e "$1" tmp/*.txt | wc -l)

echo $count

 

output:

count = 11

 

--------------------------------------------------------------------------------------------------------------------------



High scores! Tasks:- You have been provided with the following a file named prog.txt at the location /tmp/prog.txt You need to: 1.) echo the names of top 3 scorers ( Concatenated first and last names). 2.) Use the following commands: cut, sort, grep. The participant list has some records in a fixed format and has the following structure. prog.txt: RegID | Name | Sex | EmailID | Score Note: Display the output in the same sequence as they appear in the file Sample Input Data: File (/tmp/prog.txt): 2031 | Alexa Andrews | F | sleyaAolavmysong.com | 2000 4092 | Beth Barrista | M | starbucksbeth@berkley.cu | 185 Sample output:- AlexaAndrews BethBarrista
 solution :
1.) cut -d '|' -f2,5 /tmp/prog.txt | sort -t '|' -k 2 -nr | head -n 3 | cut -d '|' -f 1 | grep -oP '\S+\s\S+' | tr -d ' ' 2.) cut -d '|' -f2,5 /tmp/prog.txt | sort -nr -k4 |head -n 3 | cut -d '|' -f1 | tr -d [:blank:] (Preferable)





1. Alarum :--- read a grep_-i_-n_"$a"_ ./tmp/introduction.txt_|_ awk_-F_:_'{printf "%s:%s_",$1,$2}’
2. Belegured :-- grep_-il_"Belegured"_./tmp/*.txt_|_wc_-l
3. The:-- 1.) grep_-i_’^The’_./tmp/file.txt or 2.) grep -wi ‘^The*’ ./tmp/file.txt
4. High: sort_-t_’|’_-n_-r_-k5_./temp/prog.txt_|_cut_-d_’|’_-f2_|_head_-n_3_|_tr_-d_’_’_|_sort_-k1
 1.) cut_-d_'|'_-f2,5_/tmp/prog.txt_|_sort -t_'|'_-k_2_-nr_|_head_-n_3_|_cut_-d_'|'_ f_1_|_grep_-oP_'\S+\s\S+'_|_tr -d_'_’
 2.) cut_-d_'|'_-f2,5_/tmp/prog.txt_|_sort_-nr_-k4_|head_-n_3_|_cut_-d_'|'_-f1_|_tr_ d_[:blank:] 






Shell Programming: You have been provided with the following: A file named prog.txt at the location /tmp/prog.txt You need to: echo the names of top 3 scorers (concatenated first and last names) Use the following commands: cut, sort, grep The participant list has some records in a fixed format and has the following structure: RegID | Name | Sex | EmailID 2031 | Alexa Andrews | F | alexa@playmysong.com | Score | 86 4092 | Beth Barrista | M | starbucksbeth@berkl.com | 31 1113 | Charlie Cabello | M | shawnmendes@cabel.com | 32 2947 | Dean Denver | F | dean-d@jurassic.com 3900 | Eddie Ericsson | M | ericsson@sony.com | | 33 34 3271 | Fiona Ferguson | F | shreksfiona@outlook.com | 35
 sample Output: AlexAndrews BethBarrista CharlieCabello
 Answer :

 cut -d '|' -f 2 /tmp/prog.txt | sort -t '|' -k 5 -n -r | head -n 3 | cut -d ' ' -f 2,3

 or

 cut -d '|' -f 2 /tmp/prog.txt | sort | cut -d ' ' -f 2,3 | grep -v '^$' | head -n 3 | tr -d ' ' 





1) Firstname+ lastname (Table jaisa Unix code)

 Ans 1) sort -t "|" -k5,5nr prog.txt (location of file) | head -n 3 | cut -d "|" -f 2 | awk -F ' ' '{print $1 $2}' | sort
 Ans 2) sort -t '|' -n -r -k5 /tmp/prog.txt | cut -d '|' -f 2 | head -n 3 | tr -d ' ' | sort -k1


 2) Alarum.sh

 Ans1) grep -n "$1" introduction.txt | tr '\n' ' ' | sed 's/:/:/g' && echo
 Ans2) grep -n "$1" introduction.txt | awk -F: '{printf "%s:%s ", $1, $2} END{print " "}'

 3) Statement starting with “The”
 input_file=the.txt (location of the file)
 grep -i '^the' "$input_file"



High score GPT

cut -d '|' -f 2,5 /tmp/prog.txt | sort -t '|' -k 2 -n -r | head -n 3 | cut -d '|' -f 1 | tr -d ' '



Comments