Sponsored Content
Top Forums Shell Programming and Scripting Alternative to the loop is needed Post 302657059 by niladri29 on Saturday 16th of June 2012 02:42:31 AM
Old 06-16-2012
Hi all,
First of all a big thnx to Jim Mcnamara who personally added code tags throughout my very long initial post. Smilie
Secondly, pfb an approach that I have followed to arrive at some part of the solution:

a) Separate out all the jms ids that are occuring more than once (in my file it's twice) from main file, i.e. idout.

Code:
 
awk '{arr[$7]++}END{ for(i in arr) {if(arr[i]>1){print i}}}' idout > out
awk -F ':' '{print $3}' out > out_jmsid_mod

b)Now pick up only those lines with these jms ids (from main file, i.e idout):

Code:
fgrep -f out_jmsid_mod idout > final_entry_exit

So , the single line (i.e. one that is out of pair) are left out.

c)Now, to find the time diff between 2 consecutive data lines:
For each line in final_entry_exit file:
  • Convert the min,sec and milli secs data to nearest miilsecs (separate out this data)
  • Separate out jms id from that line (separate out this data)
  • Separate out message object id for that line
  • Sort thos data on jms id
Code:
awk -F ':' '{print$3*60*1000 + substr($4,1,3)*1000 + substr($4,4,3) echo ":"substr($6,1,48) echo ":" substr($9,25,10)}' final_entry_exit > req_data 
sort -t ':' -k 2 req_data > sorted_req_data

The output obtained looks like:

2606:c9e2c3c6c100000000460000c425bdfe3c635050c3f5f5f0:
2463:c9e2c3c6c100000000460000c425bdfe3c635050c3f5f5f0:2071362422
6451:c9e2c3c6c100000000460000c425c5853c635088c3f5f5f0:
6336:c9e2c3c6c100000000460000c425c5853c635088c3f5f5f0:2034858313
As can be observed, lines are coming in pairs. Now I require to subtract 1st column of every even line from 1st column of every odd line to find time diff.

Quote:
i.e: 2606-2463
6451-6336
and so on.

Required output

143,c9e2c3c6c100000000460000c425bdfe3c635050c3f5f5f0
115,c9e2c3c6c100000000460000c425c5853c635088c3f5f5f0

This can be done through excel, but was just wondering if someone can guide me doing this in unix. Thanks in advance.

regards,
Niladri

Last edited by niladri29; 06-16-2012 at 04:04 AM.. Reason: Adding tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

loop alternative?

I have a 1-column file with random numbers. this script runs to subtract 1 to the number and written to a file. With over 10,000 lines, it takes >2 minutes to complete the loop operation. is there an alternative awk/sed for looping to reduce the wait? Thanks! #!/bin/ksh for N in `cat... (2 Replies)
Discussion started by: apalex
2 Replies

2. UNIX for Dummies Questions & Answers

Alternative for a while read line loop

HELLO all :), I have been trying to use a simple while loop to read a file " templist", line by line and perform an action. See the code below. The reason for not using a while read line loop is the for the use of the if condition that wouldn't work. I would appreciate some ideas as this has... (2 Replies)
Discussion started by: kabs
2 Replies

3. Shell Programming and Scripting

help with while loop or any other alternative?

i=1 while do mm=02 dd=03 yy=2008 echo "$mm$dd$yy" i=$(( i+1)) echo "$i" done whenever i execute the script above i will get the error below: syntax error at line 30: `i=$' unexpected (3 Replies)
Discussion started by: filthymonk
3 Replies

4. UNIX for Dummies Questions & Answers

For loop help needed

Hi there, i want to direct the out put return from the FOR loop statement to any log file. code copied below. for file in `ls *.in` do ... ... done if there is no file then i need to write the log to one file. Thanks Arun (3 Replies)
Discussion started by: arund_01
3 Replies

5. Shell Programming and Scripting

loop needed?

Hi All, thanks in advance for any help you can give me. I'm trying to get some error checking of a username in my shell script. While I have that part under control, at the moment my script just exits if the username entered doesn't match the correct syntax. I've been googling to try and... (4 Replies)
Discussion started by: adarii
4 Replies

6. UNIX for Advanced & Expert Users

Alternative needed for joining lines with a match

Hi, The following sed command is not working for me, does anyone have a good alternative for joining lines in a file based on a match? # if a line ends with a backslash, append the next line to it sed -e :a -e '/\\$/N; s/\\\n//; ta' (6 Replies)
Discussion started by: greptastic
6 Replies

7. Shell Programming and Scripting

if loop help needed

Dear All, Please help me out for the below query echo 'please input file type (i.e file1,file2,file3,file4): ' read a cat hello.wri | grep $a | wc -l > temp1.wri cat hello.wri | grep $a | wc -l > temp2.wri cat hello.wri | grep $a | wc -l > temp3.wri cat hello.wri | grep $a | wc -l >... (1 Reply)
Discussion started by: jojo123
1 Replies

8. Shell Programming and Scripting

While Loop Syntax help needed

Hi everyone, Can ny1 help me out regarding while loop arguments i.e. what does -gt -ge -lt -le means? actually i am new to while loops (2 Replies)
Discussion started by: jojo123
2 Replies

9. Shell Programming and Scripting

'for' loop advice needed ....!!

/usr/sbin/ifconfig -a | grep "inet" | grep -v "inet6" | grep -v "127.0.0.1" | grep -v "0.0.0.0"|grep -v "192.168.100.2" | awk '{print $2}' I use above command to get IP addresses on AIX boxes.Values coming here are set to a variable "Host IPs.IP Addresses" in my fingerprinting engine. ... (4 Replies)
Discussion started by: ak835
4 Replies

10. UNIX for Advanced & Expert Users

'for' loop advice needed....!!

Scenario: Command used to capture IPs on a host: /usr/sbin/ifconfig -a | grep "inet" | egrep -v "inet6|0.0.0.0|192.168.100.2" | awk '{print $2}' Following for loop used to capture interface names: for INTERFACE in `/usr/sbin/ifconfig -a | nawk '$1 ~ /:$/ && $1 {sub(":$", "", $1); print... (3 Replies)
Discussion started by: ak835
3 Replies
All times are GMT -4. The time now is 07:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy