awk with Grep and Sort


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions awk with Grep and Sort
# 1  
Old 10-19-2014
Computer awk with Grep and Sort

1. The problem statement, all variables and given/known data:
Please bare in mind I am a complete novice to this and have very very basic knowledge so please keep any answers as simple as possible and explain in terms I will understand ahha SmilieSmilie


I have a text file of names and test scores called class.txt e.g.


Code:
Code:
Bob Smith 15
James Jones 25
Emily Hunt 70

Then another text file with more detail called classdetails.txt e.g. (note the subject, date, first and surname, class, scores are separated by tabs, also the names are one field not two)


Code:
Code:
Maths     10/05/12     Bob Smith      Class 5      65:54:32:96
English   15/04/12     James Jones   Class 7     84:64:83:38
Science   12/07/13     Emily Hunt     Class 9      73:28:95:07
History    04/08/11    Bob Smith      Class 5      74:29:73:09

Then finally a text file called test.txt that simply contains

Code:
qwertyuiop

6)Print all of the contents of the file (class.txt) and give a title to each column and separate out each column with a tab, send the output to another file.

7)Print out all of the students who have scored over 30 and redirect the output to sort to display alphabetically.

8)Print out all of the students and redirect the output to sort to display in order of their score.

12)Using the classdetails.txt file print col 5 and then sort the output in numerical order. Note this file is tab separated – hint use sort to sort the output from awk.

13)Create 4 files with the suffix .txt in your home directory. Create a sub-directory. Using awk and the UNIX shell move all of the .txt files to the sub-directory.

14) Create 4 files with the suffix .txt in your home directory. Create a sub-directory. Using awk and the UNIX shell move all of the .txt files to the sub-directory.

For the following tasks create an awk script file to do the task

15) Using the classdetails file calculate and print out the max and min values for the final column the race times.

16) Using the classdetails file print out the number of lines that contain “Vettel”.


17) Count the number of times each student appears in the file, display the number and the total number of records in the file.


2. Relevant commands, code, scripts, algorithms:

I have a very basic knowledge of things like awk, grep, sort and pipes but other than that I'm clueless.

3. The attempts at a solution (include all code and scripts):

To print all of the contents of the file I have tried
Code:
awk ‘{print}’ class.txt > class2.txt

and then perhaps edit the file with nano although I'm sure there is a better way.

Question 7 I imagine is largely similar to 6 except instead of the " > class2.txt" perhaps something involving pipes ?? I have also tried
Code:
awk -F":" '{ print $0 }' textile.txt

Question 8 the same as above except using pipes to sort i.e.
Code:
| sort -l

Question 12 will be similar to 6 I think

Question 13,14,15,16,17 I honestly have no idea where to start, I have today learnt how to write very basic scripts in nano and then use chmod u+x "script name" and then how to execute the script but as previously stated my hours of experience still probably are single figures Smilie

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Northern Illinois University, DeKalb (IL), United States, Raymond Ege, CSCI330

Last edited by jim mcnamara; 10-19-2014 at 07:46 PM..
# 2  
Old 10-19-2014
We don't need two threads discussing one homework problem. Continue this discussion here: awk questions using sort and grep
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep -v -f and sort|diff which way is faster

Hi Gurus, I have two big files. I need to compare the different. currently, I am using sort file1 > file1_temp; sort file2 > file2_tmp diff file1_tmp file2_tmp I can use command grep -v -f file1 file2 just wondering which way is fast to compare two big files. Thanks... (4 Replies)
Discussion started by: ken6503
4 Replies

2. Homework & Coursework Questions

awk questions using sort and grep

1. The problem statement, all variables and given/known data: So i'll probably get told off for this but I have a few problems and rather than clog up the whole forum I'll post them here. Please bare in mind I am a complete novice when it comes to all this and so if you help please treat me like a... (4 Replies)
Discussion started by: jamesb18
4 Replies

3. Shell Programming and Scripting

How to sort grep result based on timestamp?

Hi, Trying to sort grep result based on timestamp of the filename. I have the following result and want to sort them on timestampgrep -i 'ERROR' *log*2013* s_m_xxx_xxx_xxx_xxx_xxxx.log.20130906092431:TRANSF_1_1_1> DBG_21216 Finished transformations for Source Qualifier . Total errors ... (5 Replies)
Discussion started by: bobbygsk
5 Replies

4. Homework & Coursework Questions

Grep and Sort

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1. Print the number of people that are in the /etc/passwd file with the name of George 2. Sort by name and... (8 Replies)
Discussion started by: Jagst3r21
8 Replies

5. Shell Programming and Scripting

grep from 3 lines and sort

Pseudo name=hdiskpower54 Symmetrix ID=000190101757 Logical device ID=0601 state=alive; policy=SymmOpt; priority=0; queued-IOs=0 ============================================================================== ---------------- Host --------------- - Stor - -- I/O Path - -- Stats --- ### HW... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

6. Shell Programming and Scripting

Grep empty space and sort

Hi Expert, Kindly request for your expertise in this matter. I have below output: 12.125.124.173,xx1.common.com 12.125.124.174,xx2.common.com 12.125.124.175,xx3.common.com 12.125.124.176, 12.125.124.177, 12.125.124.178, 12.125.124.179,xx4.common.com 12.125.124.180,xx5.common.com... (8 Replies)
Discussion started by: regmaster
8 Replies

7. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

8. Shell Programming and Scripting

history awk grep sort

can someone help me in the awk part...little confuse on that part. The problem is this: what input each utility gets and what it does with data and what output is provides to the next utility) history | awk '{a++}END{for(i in a){print a " " i}}' | sort -rn | grep '^' Thanks (4 Replies)
Discussion started by: Learnerabc
4 Replies

9. Shell Programming and Scripting

how to grep sort userids

hello folks i have a file that have data like /test/aa/123 /test/aa/xyz /test/bb/xyz /test/bb/123 in above lines i just wants to grep "aa" and "bb". Thanks, Bash (4 Replies)
Discussion started by: learnbash
4 Replies

10. UNIX for Dummies Questions & Answers

Sort/Grep Question

Hello all, I have a test file that has the format: ..... O 3.694950 -.895050 1.480000 O 5.485050 .895050 1.480000 Ti -4.590000 4.590000 2.960000 Ti -2.295000 ... (5 Replies)
Discussion started by: aarondesk
5 Replies
Login or Register to Ask a Question