Analyze Historical Commands Using Stream Redirection
Requirements
Your task is to analyze a file containing a record of command usage. You need to identify the top three most frequently used commands in the file and save the results in /home/labex/project/result
. This task must be accomplished using stream redirection techniques.
Tasks
- Process the
data1
file located in /home/labex/project/
using the awk
, sort
, uniq
, and head
commands in combination with stream redirection.
- Redirect the top three most frequently used commands to
/home/labex/project/result
.
- Format the results to include both the number of occurrences and the command, as "count command" (e.g., "100 ls").
Example
Sample content of the data1
file:
895 echo $?
896 openstack compute service list
897 cd /home/chy/openstack/
898 . admin-openrc
Expected output format in /home/labex/project/result
:
150 openstack
114 systemctl
105 ls
Only the top three most frequently used commands should be included in the result file.
Hints
You may need to use awk
to extract the command from the file content. Here are some useful awk
examples:
awk '{print $2}'
: Prints the second field of each line.
awk '{print $1, $2}'
: Prints the first and second fields of each line.