"execution problem with perl"

hi everyone,

before stating my problem ,
i just want to say
thanks in advance for the time and trouble taken:-)

i am an newbie to perl programming,
the problem is a text file needed to be parsed,
i have looked over regular expressions and string matching but coudnt helped out..
the text file contained the format:-

A,1,B
A,2,B
A,1,C
C,1_1,A
B,2,D
B,1_1,A
B,2_2,A
B,2_2,D

after doing the required parser, the output must be in the following format shown below

A,1,B
B,1_1,A
A,2,B
B,2_2,A
A,1,C
C,1_1,A
B,2,D
D,2_2,D

can anyone let me know how to get the above required format?

thanks
raghuraipur

Is there any logic behind the ordering in the input and output? Sorry, I don't see it... you might wanna be more specific -- you'll improve your chances of getting the help you need.
What features are you trying to parse upon?

thanks for replying mirni,

there is no logic in order, of input...
let us assume
A-source
1-message
B-destination..

so whenever we parse message, eg-1;
it should print all the messages passing between sources and destination..
after getting parsed ,it should print reponses from the destination
for eg-
if A,1,B is first line then,
B,1_1,A
should immediately follow after the first line,
and hence there is some logic in getting the output
it is something like, B is sending some response ACK for the message 1 to A

and same follows to other inputs..
input file
A,1,B A,2,B A,1,C C,1_1,A B,2,D B,1_1,A B,2_2,A B,2_2,Dafter parsing
A,1,B B,1_1,A
A,1,C C,1_1,A
A,2,B B,2_2,A B,2,D D,2_2,Dthis is the required output:-):slight_smile:

thanks and regards
raghuraipur

OK... I think I'm starting to understand. You just need to reshuffle the lines so that the A-msg-B is followed by B-msg_msg-A.

Try this. Not super efficient, but should work:

IFS=',' 
while read src msg dst ; do 
  [[ $msg =~ _ ]] && continue 
  echo $src,$msg,$dst 
  grep "${dst},${msg}_${msg},${src}" responses.txt
done < responses.txt

where responses.txt is your input file

hi mirni,

thanks for that,
but my task is being assigned to be deal with perl, scripting..
could you help oout for the same..

thanks in advance
raghuraipur