Perl使用cut,grep,uniq的方式 [英] Perl way of using cut,grep,uniq

查看:171
本文介绍了Perl使用cut,grep,uniq的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Perl脚本中运行Perl脚本,脚本的输出是这样的

I am running a Perl script inside a Perl script, and the output of the script is something like this

# 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

我需要得到这样的输出

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

是否有Perl方式做到这一点?

Is there a Perl way to do this?

推荐答案

perldoc perlrun 将教你如何钓鱼:

perldoc perlrun will teach you how to fish:


  • -n 逐行读取文件

  • -a 将每一行拆分为 @F (并模拟 cut

  • 列表切片以访问存储在 @中的项目F 模拟 cut -f 标志

  • regex有条件模拟 grep

  • 使用哈希键模拟 uniq

  • -n to read in a file line by line
  • -a to split each line into @F (and emulate cut)
  • list slices to access items stored in @F to emulate cut's -f flag
  • regex conditional to emulate grep
  • use hash keys to emulate uniq

这篇关于Perl使用cut,grep,uniq的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆