以perl方式使用cut,grep,uniq

时间:2017-02-14 17:25:28

标签: arrays perl split grep

我在Perl脚本中运行Perl脚本,脚本的输出是这样的。这些值存储在数组

function add_posts()
{

 $season_request    = 'https://somedomain/api/info';

$args = array(
'headers' => array(
    'Authorization' => 'Basic ' . base64_encode( user . ':' . password)
)
);
$season_response = wp_remote_get( $season_request, $args );
 $season_data = json_decode($season_response['body']);

if(! $season_data)
return false;

$query = array(
  'meta_query' => array(

    array(
         'key' =>'season_id',
         'value' => $season_data->id
    )
),

'post_type' => 'seasons',
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit'),
  'posts_per_page' => 1
 );

   $season = get_posts($query);
   $season_id = '';
   if($season)
   $season_id = $season[0] -> id;

   $season_post = array
  (
    'ID' => $season_id,
    'post_title' => $season_data -> startDate . endDate . 'test',
    'post_type' => 'seasons',
    'post_author' => 1,
    'post_status' => ($season) ? $season[0] -> post_status : 'publish'

   );

   $season_id = wp_insert_post($season_post);



  }

我需要得到像这样的输出

# 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

是否有Perl方法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

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

你在寻找这个答案吗?