Homework of week 6 (Submission deadline: 23:59, Oct. 14, 2025)
If your scripts create temporary files during execution, remember to delete those temporary files at the end of the scripts.
- Write a shell script to do statistics for the user login time at Ukko during Sep. 01 - Oct. 19, 2022, according to the file
~jsyu/202209-10.log at Ukko (md5sum of this log file is: 29db07be08d403cc8d2127151b88299e). The format of login time inside the parentheses is (dd+hh:mm).
Also sort the final statistics according to decresing login time, in the aligned format of, for example:
jsyu 22 Days 22 Hours 22 Minutes
u0317011 11 Days 11 Hours 1 Minutes
u123456789 10 Days 2 Hours 20 Minutes
......
- According to the table of atoms,
- Write a script to sort the table according to the atomic number (in the order of increasing), and write it to another HTML table that only contains three columns of data, in terms of atomic number, atom symbol and atomic mass.
- Try to find out the elements whose atomic masses do not increase with the atomic numbers, and report them in neighboring pairs. You only need to report those elements with atomic numbers ≤ 100.
You can check your answer against the periodic table at Wiki.
sdiff <(awk -F' ' '{print $2, $3, $4}' ~jsyu/atom-list.txt |sed -e 's/(//g' -e 's/)//g' | sort -k 2 -g) <(awk -F' ' '{print $2, $3, $4}' ~jsyu/atom-list.txt |sed -e 's/(//g' -e 's/)//g' | sort -k 3 -g)
- Watch the MV.
References:
Sample loop without numeric index:
for i in `cat /etc/passwd | cut -d : -f 1`
do echo $i ;
finger $i ;
done
The commands inside the backquotes is called command substutition. It is suggested to use $( ) instead of the backquotes.
for i in $(cat /etc/passwd | cut -d : -f 1)
do echo $i ;
finger $i ;
done
head and tail:
head /etc/passwd #Get the first 10 lines by default
head -20 /etc/passwd #Get the first 20 lines of /etc/passwd
tail /etc/passwd #Get the final 10 lines by default
tail -20 /etc/passwd #Get the final 20 lines of /etc/passwd
head -20 /etc/passwd | tail -2 #Get the 19th and 20th lines of /etc/passwd
head -20 /etc/passwd | tail -1 #Get the 20th line of /etc/passwd
You can try the combinations to get whichever lines you want from the data.