Sorting issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting issue
# 1  
Old 05-11-2015
Sorting issue

Hi All,

I am working on a huge pile of data. Its about a service initiating a call and and finishing it.

The columns that I have is:
Code:
Date          Time         URL                           Call Type           ServiceName
5/11/2015	15:00:00	http-/0.0.0.0:8091-9	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:15	http-/0.0.0.0:8091-22	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:01	http-/0.0.0.0:8091-9	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:16	http-/0.0.0.0:8091-22	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	finished call	queryPrepaidBalanceAndThresholdInfo

The end result I want is:

Code:
5/11/2015	15:00:00	http-/0.0.0.0:8091-9	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:01	http-/0.0.0.0:8091-9	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:15	http-/0.0.0.0:8091-22	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:16	http-/0.0.0.0:8091-22	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:18	http-/0.0.0.0:8091-6	finished call	queryPrepaidBalanceAndThresholdInfo


For each Service Name, I would like to have its corresponding "going to call" and "finished call" against URL sorted out.

Is there any command that can help me in this regard ?

Or does this require a complex script ?

Regard

Last edited by Don Cragun; 05-11-2015 at 06:33 PM.. Reason: Add CODE tags.
# 2  
Old 05-11-2015
Hint, sort on 1,2,3 ascending and 4 descending.
Assume test2.txt contains the data lines...

Code:
sort -k1,3 -k4,4r <test2.txt

produces...

Code:
5/11/2015 15:00:00 http-/0.0.0.0:8091-9 going to call queryPrepaidBalanceAndThresholdInfo
5/11/2015 15:00:01 http-/0.0.0.0:8091-9 finished call queryPrepaidBalanceAndThresholdInfo
5/11/2015 15:00:15 http-/0.0.0.0:8091-22 going to call queryPrepaidBalanceAndThresholdInfo
5/11/2015 15:00:16 http-/0.0.0.0:8091-22 finished call queryPrepaidBalanceAndThresholdInfo
5/11/2015 15:00:17 http-/0.0.0.0:8091-6 going to call queryPrepaidBalanceAndThresholdInfo
5/11/2015 15:00:17 http-/0.0.0.0:8091-6 finished call queryPrepaidBalanceAndThresholdInfo

Actually since you're just interested in url and not date, I'll assume the records can come in mixed... so really:

Code:
sort -k3,3 -k4,4r <test2.txt

This User Gave Thanks to cjcox For This Post:
# 3  
Old 05-11-2015
Quote:
Originally Posted by Junaid Subhani
Hi All,

I am working on a huge pile of data. Its about a service initiating a call and and finishing it.

The columns that I have is:
Code:
Date          Time         URL                           Call Type           ServiceName
5/11/2015	15:00:00	http-/0.0.0.0:8091-9	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:15	http-/0.0.0.0:8091-22	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:01	http-/0.0.0.0:8091-9	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:16	http-/0.0.0.0:8091-22	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	finished call	queryPrepaidBalanceAndThresholdInfo

The end result I want is:

Code:
5/11/2015	15:00:00	http-/0.0.0.0:8091-9	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:01	http-/0.0.0.0:8091-9	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:15	http-/0.0.0.0:8091-22	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:16	http-/0.0.0.0:8091-22	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:18	http-/0.0.0.0:8091-6	finished call	queryPrepaidBalanceAndThresholdInfo


For each Service Name, I would like to have its corresponding "going to call" and "finished call" against URL sorted out.

Is there any command that can help me in this regard ?

Or does this require a complex script ?

Regard
I don't know how you get output with an 18 in the seconds field in the output when that value does not appear in any line in your input.

It isn't clear if you are saying that your input file might contain more than one ServiceName field value (since your sample input only has one value in that field). If there is more than one value for that field, it isn't clear whether you want each value in a separate output file or just sorted in one output file.

Now that I have added CODE tags to your post (so we can see that you have tabs as field separators instead of spaces), and assuming that you really want to get rid of the header line from your input and want all of the output in one file when there is more than one ServiceName value, you could try something like:
Code:
#!/bin/ksh
{	IFS= read header
	sort -t "	" -k5,5 -k3,3 -k4,4r
} < file

(where the character between the double quotes is a single literal tab character). This was tested using the Korn shell, but will work with any shell based on Bourne shell syntax.With the sample input you provided, this produces the output:
Code:
5/11/2015	15:00:15	http-/0.0.0.0:8091-22	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:16	http-/0.0.0.0:8091-22	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:17	http-/0.0.0.0:8091-6	finished call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:00	http-/0.0.0.0:8091-9	going to call	queryPrepaidBalanceAndThresholdInfo
5/11/2015	15:00:01	http-/0.0.0.0:8091-9	finished call	queryPrepaidBalanceAndThresholdInfo

If you want the header to be copied into the output instead of removing it; add the line:
Code:
	printf '%s\n' "$header"

just before the line:
Code:
	sort -t "	" -k5,5 -k3,3 -k4,4r

in the script.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 05-11-2015
This solved my problem. Thank You so much !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

2. Shell Programming and Scripting

Need assistance with a file issue and a terminal issue

Hello everyone, I'm in need of some assistance. I'm currently enrolled in an introductory UNIX shell programming course and, well halfway through the semester, we are receiving our first actual assignment. I've somewhat realized now that I've fallen behind, and I'm working to get caught up, but for... (1 Reply)
Discussion started by: MrMagoo22
1 Replies

3. Shell Programming and Scripting

sorting issue

I have files with the name myfile_YYMMDD.txt I need to sort them by their date stamp. I know this will work. ls -lrt * | awk '{print $9}' | cut -d "_" -f3 | sort However, it just returns YYMMDD.txt I can then append the myfile_ to it. However, that myfile_ may change. How do... (1 Reply)
Discussion started by: guessingo
1 Replies

4. UNIX for Advanced & Expert Users

HELP on sorting

hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this; 192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible... (1 Reply)
Discussion started by: sam127
1 Replies

5. Shell Programming and Scripting

Sorting issue with directory and file name

Hi All, My folder contains the files as: $ ls -lrt total 50 lms_prap_rf_20100422_99.xml lms_prap_rf_20100422_9.xml lms_prap_rf_20100422_100.xml lms_prap_rf_20100422_10.xml lms_prap_rf_20100426_1.xml I need to get the sorting of the above file based on numbers. I need first file in... (5 Replies)
Discussion started by: sreejitnair123
5 Replies

6. Shell Programming and Scripting

Sorting

I've been on holiday, and the brain's clearly not back in gear yet... On Solaris, I have a simple list of package names... DGBUpPost1.43_R1 DGSApp1.44_S1 DGSApp1.47_V1 DGSApp1.48_W0 DGPEuroC1.10_K0 DGPEuroC1.11_L0 DGPEuroC1.9_J0 DGSRet1.10_K0 I just want to properly sort them into... (2 Replies)
Discussion started by: JerryHone
2 Replies

7. UNIX for Dummies Questions & Answers

Issue on sorting

Hi, I have a file which has data as path/1.xml path/2.xml,...(each in separate lines) I want to sort this file in order. It is not working when I give "sort filename" The number of "/" in path can vary. Thanks, Floyd (1 Reply)
Discussion started by: asmfloyd
1 Replies

8. Shell Programming and Scripting

Sorting Issue

Hi Guys, I am very new to Unix.Can anyone tell me how to sort a file based on fields. For example, I am having a file whose contents are mentioned below: 2233|charles harris |g.m. |sales |12/12/52| 90000 9876|bill johnson |director... (3 Replies)
Discussion started by: mraghunandanan
3 Replies

9. Shell Programming and Scripting

Sorting :

Hi .... iam having a file with 20,000 rows and 56 colums. Iam trying to sort a file ....for that iam using 'sort' command. If iam having 3 and 5 key colums etc ... as numerical this 'sort' command will work? what ihave to do ? sample example : E100|0|19940102|1|11111|E003... (3 Replies)
Discussion started by: satyam_sat
3 Replies

10. Shell Programming and Scripting

Unix Arithmatic operation issue , datatype issue

Hi, I have a shell scripting. This will take 7 digit number in each line and add 7 digit number with next subsequent lines ( normal addition ). Eg: 0000001 0000220 0001235 0000022 0000023 ........... ......... ........ Like this i am having around 1500000 records. After adding... (23 Replies)
Discussion started by: thambi
23 Replies
Login or Register to Ask a Question