2017-02-14 1 views
-4

Ich verwende ein Perl-Skript in einem Perl-Skript, und die Ausgabe des Skripts ist in etwa so. Diese Werte werden in einem Array gespeichertVerwenden von cut, grep, uniq in Perl

# 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 

Ich brauche eine Ausgabe wie diese

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

ich zur Zeit der Ausgabe des Skripts in eine Datei zu schreiben bin zu bekommen und dabei wie folgt,

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

Gibt es einen Perl-Weg, dies zu tun?

+2

Natürlich gibt es. Welches Problem hast du? – ikegami

+0

Ich habe Grep verwendet und konnte die Datenstruktur als Array beibehalten. das heißt, ich grep mit Zeichen beginnend mit # und speicherte das Ergebnis in einem Array. Ich bin neu in Perl und ich wusste nicht, wie man es als Array hält. Ich wusste nur, sie zu brechen und zu verarbeiten –

+1

Wenn Ihre [Frage wird geschlossen] (http://stackoverflow.com/q/42051608/176646), nicht erneut die exakt gleiche Frage erneut. Lesen Sie die Anleitung im nahen Grund, klären Sie Ihre Frage anhand der Kommentare anderer Leute und versuchen Sie, Ihre Frage zu verbessern, damit sie wieder geöffnet werden kann. – ThisSuitIsBlackNot

Antwort

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

Suchen Sie diese Antwort?

+0

Aber ich habe die Werte in Array und nicht in Datei –

+0

Sie könnten eine bessere Antwort erhalten, wenn Sie genauer bei der Beschreibung Ihrer Aufgabe waren. Mein Perl-One-Liner macht genau das, was Ihre Piped-Command-Kombination macht. –

+0

"Ich schreibe gerade die Ausgabe des Skripts in eine Datei und mache das wie folgt", habe ich gesagt. Aber was ich brauche, ist "Ich führe ein Perl-Skript in einem Perl-Skript, und die Ausgabe des Skripts ist in etwa so. Diese Werte werden in einem Array gespeichert" ........ Also kannst du bitte ein schau und sag es mir. Ich bin neu in Perl –