-4

I am running a Perl script inside a Perl script, and the output of the script is something like this. These values are stored in an array

# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/angyvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/aqmmgvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/69aqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/69aavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/qqmavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/wttvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/9aaqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/9aaavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/a1vqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
# aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/maaavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva
[qNFq] cqqq aarvqca qntereatqng 1qatvqnqth. heqqq 1qatvqnqth.
[qNFq] cqqq aarvqca qntereatqng fmtvqnqth. heqqq fmtvqnqth.
[qNFq] cqqq aarvqca qntereatqng gcaavqnqth. heqqq gcaavqnqth.
[qNFq] cqqq aarvqca qntereatqng gq9vqnqth. heqqq gq9vqnqth.
[qNFq] cqqq aarvqca qntereatqng hvavqnqth. heqqq hvavqnqth.
[qNFq] cqqq aarvqca qntereatqng q9vqnqth. heqqq q9vqnqth.
[qNFq] cqqq aarvqca qntereatqng 9vaqvqnqth. heqqq 9vaqvqnqth.
[qNFq] cqqq aarvqca qntereatqng mcaavqnqth. heqqq mcaavqnqth.
[qNFq] cqqq aarvqca qntereatqng mcqrvqnqth. heqqq mcqrvqnqth.
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/angyvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/aqmmgvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/69aqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/69aavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/qqmavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/wttvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/9aaqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/9aaavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/a1vqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
# aAM axac: cmt /tm9/raawV9h /myqq1fqq1er/maaavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a4.1.e.1234567891014523.ahqva
[qNFq] cqqq aarvqca qntereatqng 1qatvqnqth. heqqq 1qatvqnqth.
[qNFq] cqqq aarvqca qntereatqng fmtvqnqth. heqqq fmtvqnqth.
[qNFq] cqqq aarvqca qntereatqng 6caavqnqth. heqqq 6caavqnqth.
[qNFq] cqqq aarvqca qntereatqng 6q9tvqnqth. heqqq 6q9tvqnqth.
[qNFq] cqqq aarvqca qntereatqng q9vqnqth. heqqq q9vqnqth.
[qNFq] cqqq aarvqca qntereatqng 9vaqvqnqth. heqqq 9vaqvqnqth.
[qNFq] cqqq aarvqca qntereatqng mcaavqnqth. heqqq mcaavqnqth.
[qNFq] cqqq aarvqca qntereatqng mcqrvqnqth. heqqq mcqrvqnqth.
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/angyvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/aqmmgvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/69aqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/69aavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/qqmavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/wttvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/9aaqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/9aaavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/a1vqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva
# aAM axac: cmt /tm9/raaaRX6 /myqq1fqq1er/maaavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a7.1.e.1234567891020719.ahqva

I need to get an output like this

tm9/raaqHRW /111111111/ty9a1
tm9/raawV9h /111111111/ty9a4
tm9/raaaRX6 /111111111/ty9a7

I am currently writing the output of the script to a file and doing as follows,

grep "cmt /tm9" output_file | cut -d'/' -f2,3,9,10 | cut -d '.' -f1 | uniq

Is there a Perl way to do this?

  • 2
    Of course there is. What problem are you having? – ikegami Feb 14 '17 at 17:29
  • I used grep and was able to retain the data structure as array. that is, I grep with characters starting with # and stored the result in an array. I am new to perl and I did not know how to do it keeping it as an array. I only knew to break them and process – Vinu Shankar Feb 14 '17 at 17:33
  • 1
    If your [question gets closed](http://stackoverflow.com/q/42051608/176646), don't re-post the exact same question again. Read the guidance in the close reason, clarify your question based on other people's comments, and try to improve your question so that it can be reopened. – ThisSuitIsBlackNot Feb 14 '17 at 17:33
  • This question is an identical copy of your preceding question [*Perl way of using cut,grep,uniq*](http://stackoverflow.com/questions/42051608/perl-way-of-using-cut-grep-uniq) which was closed because it was "too broad". Why do you think this should be treated differently? – Borodin Feb 14 '17 at 19:14

1 Answers1

0
perl -F/ -nle '/cmt \/tm9/ && do { $_ = join "/", @F[1,2,8,9]; s/\..*//; print if ++$h{$_} == 1}' output_file

Are you looking for this answer?