Visit Our UNIX and Linux User Community


Sorting problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sorting problem
# 1  
Old 06-08-2011
Network Sorting problem

1) I need to reverse sort the text from lit.csv (bellow) by the second column, then save the last five lines in a text file text.txt but I'm doing something wrong so any help would be much appreciated.

I've been trying to use this:
Code:
sort --field-separator=; -b -k2g,2 lit.csv -o text.txt

2) Using the same file (lit.csv) I have to save first names from column one for those magazines released in 2006 (column 1) which don't have "No." part in the column four, to a text file author.txt

I don't even know where to begin with this one.

Code:
Agarwal R., Prasad J. (1998);A Conceptual and Operational Definition of Personal Innovativeness in the Domain of Information Technology;Information Systems Research;Vol. 9, No. $
Ajzen I. (1999);The Theory of Planned Behavior;Organizational Behavior and Human Decision Processes;Vol. 50, No. 2, pp. 179-211
Aller B. M., Phillips C., Tsang E., Kline A. A., Aravamuthan R. (2003);An online assessment system to enhance teaching and learning in engineering;Proceedings of the 33rd Annual$
Aluisio S. M., Aquino V. T., Pizzirani R., de Oliveira Jr. O. N. (2003);Assessing High-Order Skills with Partial Knowledge Evaluation: Lessons Learned from Using a Computer-base$
Biggs J. B., Kember D., Leung D. Y. P. (2001);The revised two-factor Study Process Questionnaire: R-SPQ-2F;British Journal of Educational Psychology, The British Psychological S$
Black P., William D. (1998);Inside the black box: Raising standards through classroom assessment;Phi Delta Kappan;Vol. 80, No. 2, pp. 139-148
Bostrom L., Lassen L. M. (2006);Unraveling learning, learning styles, learning strategies and meta-cognition;Education + Training;Vol. 48, No. 2/3, pp. 178-189
Bouslama F., Lansari A., Al-Rawi A., Abonamah A. A. (2003);A Novel Outcome-Based Educational Model and its Effect on Student Learning, Curriculum Development  and Assessment;Jou$
Brown J. S., Adler R. P. (2008);Minds on Fire: Open Education, the Long Tail and Learning 2.0;EDUCAUSE Review;Vol. 43, No. 1, pp. 16-32
Buzzetto-More N. A., Alade A. J. (2006);Best Practices in e-Assessment;Journal of Information Technology Education;Vol. 5, pp. 251-269
Cleaver T.G., Elbasyouni L.M. (2005);Student Online Assessment Behaviors;IEEE Transactions on Education;Vol. 48, No. 3, pp. 400-401
Compeau D. R., Higgins C. A. (1995);Computer Self-Efficacy: Development of a Measure and Initial Test;MIS Quarterly;Vol. 19, No. 2, pp. 189-211
Connolly T., Stansfield M. (2006);Using Games-Based eLearning Technologies in Overcoming Difficulties in Teaching Information Systems;Journal of Information Technology Education$
Davis F. D. (1989);Perceived Usefulness, Perceived Ease of Use and User Acceptance of Information Technology;MIS Quarterly;Vol. 13, No. 3, pp. 319-340
Davis F. D., Bagozzi R. P., Warshaw P. R. (1989);User Acceptance of Computer Technology: A Comparison of Two Theoretical Models;Management Science;Vol. 35, No. 8, pp. 982-1003
Davis F. D., Bagozzi R. P., Warshaw P. R. (1992);Extrinsic and Intrinsic Motivation to Use Computers in the Workplace;Journal of Applied Social Psychology;Vol. 22, No. 14, pp. 1$
Dennen V. P. (2008);Looking for evidence of learning: Assessment and analysis methods for online discourse;Computers in Human Behavior, Elsevier;Vol. 24, No. 2, pp. 205-219
Dolzani M., Ronchetti M. (2005);Video Streaming over the Internet to support learning: the LODE system;WIT Transactions on Informatics and Communication Technologies;Vol. 34, pp$
Eom S.B., Wen H.J., Ashill N. (2006);The Determinants of Students' Perceived Learning Outcomes and Satisfaction in University Online Education: An Empirical Investigation;Decisi$
Etling A. (1993);What is Nonformal Education?;Journal of Agricultural Education;Vol. 34, No. 4, pp. 72-76
Felder R. M., Brent R. (2005);Understanding Student Differences;Journal of Engineering Education;Vol. 94, No. 1, pp. 57-72
Flynn A., Concannon F., Campbell M. (2006);An evaluation of undergraduate students' online assessment performances;Advanced Technology for Learning;Vol. 3, No. 1, pp. 15-21
Forbes H., Duke M., Prosser M. (2001);Students` perceptions of learning outcomes from group-based, problem-based teaching and learning activities;Advances in Health Sciences;Vol$
Ford M., Morice J. (2003);How Fair are Group Assignments? A Survey of Students and Faculty and a Modest Proposal;Journal of Information Technology Education;Vol. 2, pp. 367-378
Gibbs G., Simpson C. (2004);Does your assessment support your students' learning?;Learning and Teaching in Higher Education;Vol. 1, No. 1, pp. 1-31
Gregorc A. F., Butler K. A. (1984);Learning is a matter of style;Vocational Education Journal;Vol. 59, No. 3, pp. 27-29
Kember D., Leung D. Y. P. (1998);The dimensionality of approaches to learning: An investigation with confirmatory factor analysis on the structure of SPQ and LPQ;British Journal$
Khare A., Lam H. (2008);Assessing Student Achievement and Progress with Online Examinations: Some Pedagogical and Technical Issues;International Journal on E-Learning;Vol. 7, No$
Knight P. (2002);Summative assessment in higher education: practices in disarray; Studies in Higher Education;Vol. 27, No. 3, pp. 275-286
Koohang A., Durante A. (2003);Learners' Perceptions toward the Web-based Distance Learning Activities/Assignments Portion of an Undergraduate Hybrid Instructional Model;Journal $
Lizzio A., Wilson K., Simmons R. (2002);University Students' Perceptions of the Learning Environment and Academic Outcomes: implications for theory and practice;Studies in Highe$
Macdonald J. (2004);Developing competent e-learners: the role of assessment;Assessment & Evaluation in Higher Education;Vol. 29, No. 2, pp. 215-226
Marton F., Saljo R. (1976);On qualitative differences in learning: I. Outcome and process;British Journal of Educational Psychology;Vol. 46, pp. 4-11
Moore G. C., Benbasat I. (1991);Development of an Instrument to Measure the Perceptions of Adopting an Information Technology Innovation;Information Systems Research;Vol. 2, No.$
O'Neill K., Singh G., O'Donoghue J. (2004);Implementing eLearning Programmes for Higher Education: A Review of the Literature;Journal of Information Technology Education;Vol. 3,$
Oliver D., Dobele T. (2007);First Year Courses in IT: A Bloom Rating;Journal of Information Technology Education;Vol. 6, pp. 347-360

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 06-08-2011 at 01:24 PM.. Reason: code tags, please!
# 2  
Old 06-08-2011
I bet your problem is the unquoted ;. The shell will take that as a separator and break it into two commands: 'sort --field-separator=' and '-b -k2g,2'

I think all you need for -k is -k 2,3.

The last 5 lines can easily be done with tail.

sort --field-separator=';' -k 2,3 < input | tail -n 5 > output

Also, I think -t is more portable than --field-separator. The long-style option would be in GNU sort only.
# 3  
Old 06-08-2011
as for the second point:
Code:
nawk -F';' '$4!~"No." {n=split($1,f1, "[,()]"); if (f1[n-1] != "2006") next;for(i=1;i<n-1;i++) {match(f1[i], "[A-Za-z][A-Za-z]*");print substr(f1[i],RSTART, RLENGTH)}}' lit.csv

# 4  
Old 06-08-2011
Does your sort work as you want?

You can grep to filter and then cut:
Code:
grep -v '^[^;]*(2006);[^;]*;[^,]* No\.' yourfile | cut -d ';' -f 1 |cut -d '(' -f 1

but for fields and subfields, awk/nawk seems like a good candidate. Also, do you want the multiple authors on separate lines? I am a sed guy, not awk, and it can do all of this, even though it is not field oriented:
Code:
sed '
  /^[^;]* (2006;/!d
  /^[^;]*;[^;]*;.* No\. /d
  s/ (.*//
  s/,/ \
/g
 ' yourfile | sort -u

# 5  
Old 06-09-2011
Thanks for the help. I appreciate it.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #158
Difficulty: Easy
The migration of the ARPANET to TCP/IP was officially completed on January 1, 1983, when the new protocols were permanently activated.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem with sorting in shell script

Hi, I have the following list: 42A 42AA 42B 42BB 42AAA 42BBB 49A 49AA 49B 49AAA 49BB I need it to be sorted as following: 42A 42B (2 Replies)
Discussion started by: sairamtejaswi
2 Replies

2. UNIX for Advanced & Expert Users

Sorting problem

I have data like this in file Now I have to sort using second column(usage) and i should get first column against it post sorting please provide input (2 Replies)
Discussion started by: mirwasim
2 Replies

3. UNIX Desktop Questions & Answers

Problem in sorting a text file

Hi; I have a text file like this: 1 10 11 2 3 4 M X Y When I sort it numerically using sort -n, it looks like this: Y X M 1 2 3 4 10 (3 Replies)
Discussion started by: a_bahreini
3 Replies

4. UNIX for Dummies Questions & Answers

Sorting file with columns (problem)

Hi all! I am new to Unix programming so bare with me please :). I have saved the output of my results in a file called testfile which contains 3 columns a 15 rows. e.g. 175 754 abvd 948 454 fewf 43 754 fewc 6 734 feww xxx xxx xxxx I want to sort the contents of this file... (10 Replies)
Discussion started by: daelas
10 Replies

5. Shell Programming and Scripting

Sorting problem (SunOS 5.9 / KSH).

Hi, Can someone tell me why the "LargeFile" is coming first before the smaller files. Is there any way to list the files based on size column. ls -g| sort -k 4 -rw-r--r-- 1 user 6117910528 Apr 28 15:04 LargeFile -rw-r--r-- 1 user 6136832 May 30 07:23 my_20080530.tar -rw-r--r-- ... (2 Replies)
Discussion started by: kesari
2 Replies

6. UNIX for Dummies Questions & Answers

Sorting problem

Hai , In unix we are going to sort it out all the directories and files based on size of the file. For that we have to use this command ls -al | sort +4nr. If we are giving this command means it will show all the records in a descending order....when I am checking one file bytes its... (4 Replies)
Discussion started by: cool4naren
4 Replies

7. HP-UX

Sorting problem....

hey mate. ive got a sorting problem that i would like to share... i made a script that sorts the bdf command and redirected the output to a file. the output of the file is: 691416 34% / 851552 7% /stand 7203048 31% /var 23637584 26% /var/adm/crash 2968864 ... (4 Replies)
Discussion started by: jarod004
4 Replies

8. Shell Programming and Scripting

sorting/arrangement problem

Hi, I have the following 'sorting' problem. Given the input file: a:b:c:12:x:k s:m:d:8:z:m a:b:c:1:x:k p:q:r:23:y:m a:b:c:3:x:k p:q:r:1:y:m the output I expect is: a:b:c:1:x:k p:q:r:1:y:m s:m:d:8:z:m What happened here is I grouped together lines having the same values for... (7 Replies)
Discussion started by: Abhishek Ghose
7 Replies

9. Shell Programming and Scripting

Sorting/Filed Defining/Output problem

need a little help with a few tid bits. I wrote a script that checks the resoluion of image files and writes them out to a file then sorts the resolutions by largets Width. Then take the sorted files information and toss all the 835 widths into a seperate file. Ignore the redundancies its a... (1 Reply)
Discussion started by: TiredOrangeCat
1 Replies

10. Shell Programming and Scripting

Problem in sorting the file

file format is word filename no.of occurances ------------------------------ wish f3.txt 2 wish f2.txt 1 cold f1.txt 5 cold f2.txt 3 cold f1.txt 3 cold e.txt 3 gold f1.txt 7 gold f3.txt 3 rush e.txt 2 itz abt building a search index for every word in the files given as input the... (1 Reply)
Discussion started by: vishnu_vaka
1 Replies

Featured Tech Videos