sort the last names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort the last names
# 1  
Old 09-13-2010
sort the last names

hi all

i have a datafile consists of fields seperated by colons. the fields are as follows : a) First and last name
b) Phone number
c) Address
d) Birth date
e) Salary

now i want to write a script naming lookup.sh using vi editor which consists of following operations:

a) sort the data files by last names
b) show the user the content of the datafile
c) Display the user the number of entries
in the file

...
# 2  
Old 09-13-2010
Post your sample input file and expected output.
# 3  
Old 09-13-2010
i have a input file naming lookup.txt and the data is :

Code:
sonu pal:9897933005:pimpri:19/05/1988:15000
vijay aggarwal:9897933006:akurdi:19/05/1987:20000
ajay singh:9897933007:dapodi:19/05/1986:25000
mahesh rana:9006752312:chinchwad:21/09/1976:50000


and the expected o/p must be like this :


Code:
vijay aggarwal:9897933006:akurdi:19/05/1987:20000
sonu pal:9897933005:pimpri:19/05/1988:15000
mahesh rana:9006752312:chinchwad:21/09/1976:50000
ajay singh:9897933007:dapodi:19/05/1986:25000


the number of entries in a line = 5
total number of entries in a file = 20

Last edited by pludi; 09-13-2010 at 04:51 AM..
# 4  
Old 09-13-2010
Hi, Try this,

Code:
sort -k2 inputfile ; awk -F":" 'END{print "the number of entries in a line =" NF; print "total number of entries in a file = " NF*NR}' inputfile

# 5  
Old 09-13-2010
hi pravin27,

It is showing the output like this ...but the output of last two lines are zero which is incorrect...


vijay aggarwal:9897933006:akurdi:19/05/1987:20000
sonu pal:9897933005:pimpri:19/05/1988:15000
mahesh rana:9006752312:chinchwad:21/09/1976:50000
ajay singh:9897933007:dapodi:19/05/1986:25000
the number of entries in a line =0
total number of lines =0

Last edited by sonu_pal; 09-13-2010 at 05:26 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sort a text file based on names in square brackets

Hi all, I have a text file similar to this: Text More text Etc Stuff That Is Needed Etc Etc This contains over 70 entries and each entry has several lines of text below the name in square brackets. (5 Replies)
Discussion started by: Scally
5 Replies

2. Shell Programming and Scripting

File Move & Sort by Name - Kick out Bad File Names & More

I have a dilemma, we have users who are copying files to "directory 1." These images have file names which include the year it was taken. I need to put together a script to do the following: Examine the file naming convention, ensuring it's the proper format (e.g. test-1983_filename-123.tif)... (8 Replies)
Discussion started by: Nvizn
8 Replies

3. Shell Programming and Scripting

Sort html based on .jar, .war file names and still keep text within three groups.

Output from zipdiff GNU EAR comparison tool produces output in html divided into three sections "Added, Removed, Changed". I want the output to be sorted by jar or war file. <html> <body> <table> <tr> <td class="diffs" colspan="2">Added </td> </tr> <tr><td> <ul>... (5 Replies)
Discussion started by: kchinnam
5 Replies

4. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Reverse the order of a list of file names (but not sort them alphabetically or numerically)

Hello all, I have a list of file names in a text document where each file name consists of 4 letters and 3 numbers (for example MACR119). There are 48 file names in the document (they are not in alphabetical or numerical order). I would like to reorder the list of names so that the 48th name is... (3 Replies)
Discussion started by: MDeBiasse
3 Replies

6. Shell Programming and Scripting

Sort names in a list by order of importance

Hi, I have multiple list which is arranged by order of importance. I need to do sorting on these lists based on the last name of the user(initial), if user name does not have initial then first name is initial . Important thing is that the last name in the list is important. If there is two or... (1 Reply)
Discussion started by: pratapsingh
1 Replies

7. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

8. UNIX for Dummies Questions & Answers

How can I sort the file names in the directory

Hi , I have a list of files in the directory I want to sort based on the file name. But in the middle of filename contains the number based on that I need to sort.Could you suggest me on the same? Example filenames: /user1$ls RS.DEV.ISV.F1.RS.REFDATA.DATA... (1 Reply)
Discussion started by: praveen.thumati
1 Replies

9. UNIX for Dummies Questions & Answers

Sort directory with complex numeric file names

I have a directory with a large number (1000s) of files and I need to produce a file listing all the files in the directory ordered "properly" (properly will be explained shortly). The files have the following naming pattern: bul_13_5_228_b.txt bul_1_3_57.txt bul_13_6_229.txt... (2 Replies)
Discussion started by: fdsayre
2 Replies

10. Shell Programming and Scripting

How to sort directory names and use only last?

I need help writing a bash script for the windows cygwin environment. I'm not sure if bash is the optimal tool. Perhaps perl would be better? Either would work. I have directories whose names include the date they were created. The directory names are in the format of... (0 Replies)
Discussion started by: siegfried
0 Replies
Login or Register to Ask a Question