1.Consider the file below: -bash-3.2$ cat info 012-34-5678 Ambercrombie, Al 01/0
ID: 3875700 • Letter: 1
Question
1.Consider the file below:
-bash-3.2$ cat info
012-34-5678 Ambercrombie, Al 01/01/72 555-1111
123-45-6789 Barton, Barbara 02/02/73 555-2222
234-56-7890 Canby, Charles 03/03/74 555-3333
345-67-8901 Danfield, Deann 04/04/75 555-4444
Provide the command to extract the names only
Display the names and phone numbers
Repeat the above and save to a file
2.Consider the file /etc/group:
Group : password : Group ID : Group List
Provide the command to:
Display the list of sudo users (i.e. users in admin group) in alphabetical order
Check for duplicated group ID
3.Using cut and paste in sequence, you can change the order of columns in a table
Consider the file below:
-bash-3.2$ cat address
Elizi Moe, 5208534566, emoe@ncsu.edu
Ma Ta, 4345667345, mta@yahoo.com
Diana Cheng, 5203456789, dcheng@asu.edu
Provide the command to change the order of the phone number and email address columns
4.Consider the file whotb below:
-bash-3.2$ cat whotb
avuong1 pts/0 2017-08-25 23:00 (10.152.100.245)
pbartakk pts/11 2017-08-25 23:29 (174.17.211.48)
zzhan281 pts/3 2017-08-25 22:52 (71.223.35.124)
jgamboa8 pts/2 2017-08-25 23:05 (71.231.248.218)
pkalungi pts/1 2017-08-25 20:12 (10.143.198.41)
ramdisk pts/20 2017-08-22 17:17 (10.106.150.87)
pbartakk pts/8 2017-08-25 22:22 (10.152.112.188)
pkalungi pts/10 2017-08-25 23:18 (10.143.198.41)
5.Display only (in order) the station #, username, and date logged in order
Sort the above in increasing order of the station #
Sort the same data in reverse order
Create a file called useron that contains only the usernames
Sort the file useron in reverse order, removing the duplicate, and saving with the same filename
Insert line numbers into the file useron above, starting at 100 and in increment of 10
Explanation / Answer
Dear student,
1.
To get the second column, name from file us ethe belwo command
ls -l | awk '{print $2}'
Change the value of 2 as per the no of column.
To get the name and phone number,
ls -l | awk '{print $2}'
ls -l | awk '{print $1}'
2.
Use the below command for displaying the list of sudo users (i.e. users in admin group) in alphabetical order
cut -f1,$(sed -n "1 s/${columnname}.*//p" datafile |
sed 's/[^ *]//g' | wc -c) < datafile
3.
The command to change the order of the phone number
and email address columns, that means we will need to swap the two columns,
use the below commans for the same,
paste <(cut -f2 fileName.txt) <(cut -f1 fileName.txt)
4. And for the fourth one the question is not clear to me, can you please provide some more information like, if there are column headers to the file data.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.