Alternative to the loop is needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternative to the loop is needed
# 1  
Old 06-15-2012
Alternative to the loop is needed

I have a file containing ids like this (file1):
Code:
c9e2c3c6c100000000460000c02000803c63e529c3f5f5f0
c9e2c3c6c100000000460000c02002813c63e539c3f5f5f0
c9e2c3c6c100000000460000c02002ee3c63ebb1c3f5f5f4
c9e2c3c6c100000000460000c020042f3c63e549c3f5f5f0

These ids are present in muiltiple files named: id1 id1 id3 etc,
To find all occurances of values of file1 in id1,id2 etc, I have used:
Code:
fgrep -f file1 id* > idout

Now for each line in file1 (eg, line 1:c9e2c3c6c100000000460000c02000803c63e529c3f5f5f) there should be 2 entries in file idout, like:
Code:
Central-Perf-21-0:lppza087; [2012-06-12 21:00:02,463] <PERFA  > JMSId :ID:c9e2c3c6c100000000460000c02000803c63e529c3f5f5f0 SvcName :realtime.xltr.FASERInquire                                                                   OO [MessageListenerThreadPool : 15  ] OO xltrmdb.XltrFASERInquireMDB       OO                       logEntry() OO Entry into MDB id:9 and message object id 2071362422
Central-Perf-21-0:lppza087; [2012-06-12 21:00:02,606] <PERFA  > JMSId :c9e2c3c6c100000000460000c02000803c63e529c3f5f5f0 SvcName :realtime.xltr.FASERInquire Card :123456789123456 SrcCd :WEB                                  OO [MessageListenerThreadPool : 15  ] OO xltrmdb.XltrFASERInquireMDB       OO                        logExit() OO Return from MDB id:9 and message object id 2071362422
To be noted : (c9e2c3c6c100000000460000c02000803c63e529c3f5f5f0,2071362422)

for every two lines will be unique, like they a pair.
But there will also be few lines of file1 which will have only a single entry in idout file,like:
Code:
Central-Perf-21-0:lppza087; [2012-06-12 21:00:02,463] <PERFA  > JMSId :ID:c9e2c3c6c100000000460000c020042f3c63e549c3f5f5f0 SvcName :realtime.xltr.FASERInquire                                                                   OO [MessageListenerThreadPool : 15  ] OO xltrmdb.XltrFASERInquireMDB       OO                       logEntry() OO Entry into MDB id:9 and message object id 2111111111

Requirement:
a)How to remove (separate out). the single lines? (as depicted above)

b)How to find time lag, like (diff of 2012-06-12 21:00:02,463 and 2012-06-12 21:00:02,606) depiected above for 2 consecutive lines? Need to ensure that the lines must be of same JMS id and message id)
N.B: A loop on file1 can be executed to find occurances in id* files;.Also the time diff (subtraction) can be done in the loop.But that is not feasible due to severe time constraint as the data volume is very high.

regards,
niladri
Moderator's Comments:
Mod Comment please use code tags to allow us to read data and code


---------- Post updated at 08:10 PM ---------- Previous update was at 04:08 PM ----------

Hi Gurus,
Any hints?

thanks,
Niladri

Last edited by jim mcnamara; 06-15-2012 at 08:35 AM..
# 2  
Old 06-15-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 3  
Old 06-15-2012
Sorry, for my ignorance moderator. But I was too eager to get a help.Will surely try to adhere to rules in future.

thnx,
Niladri
# 4  
Old 06-15-2012
What is the output you want from the double-lines file? Just the list of ID's? Or the raw lines?
# 5  
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question