shell Grep输出在单独的行上[已关闭]

dba5bblo  于 2022-12-13  发布在  Shell
关注(0)|答案(1)|浏览(141)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受答案。

这个问题是由一个打字错误或一个无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
昨天关门了。
Improve this question
我有下面的脚本:

#!/bin/bash
   while read -r i; do
  autorep -j $i -q | grep -e insert_job -e date_conditions -e condition | awk '{print ($2,$4,$6)}'
echo
 done

我得到输出

Test_Kill CMD
0
Test_Karthik CMD
0
Test_Ujjal CMD
0
Test1 CMD
0

当我将脚本修改为:

#!/bin/bash
  while read -r i; do
     autorep -j $i -q | grep -e insert_job -e date_conditions -e condition | awk 'BEGIN { ORS=" " }; {print ($2,$4,$6)}'
     echo
  done

输出如下:

Test_Kill CMD  0   Test_Karthik CMD  0   Test_Ujjal CMD  0   Test1 CMD  0

我正在寻找的是,如果我可以得到如下输出:

Test_Kill CMD  0
Test_Karthik CMD  0
Test_Ujjal CMD  0
Test1 CMD  0

编辑:
下面是autorep输出

autorep -j test_ujjal -q

/* ----------------- test_ujjal ----------------- */

insert_job: test_ujjal   job_type: CMD
command: echo
machine: vservername
owner: owner
permission:
date_conditions: 0
description: "test job"
alarm_if_fail: 0
alarm_if_terminated: 0
8e2ybdfx

8e2ybdfx1#

假设您的autorep输出为:

/* ----------------- test_ujjal ----------------- */

insert_job: test_ujjal   job_type: CMD
command: echo
machine: vservername
owner: owner
permission:
date_conditions: 0
description: "test job"
alarm_if_fail: 0
alarm_if_terminated: 0

下面的awk可能适合您:

awk '/insert_job/ {printf "%s %s ", $2, $4}; /date_conditions|condition/ {printf "%s\n", $2}' < <(autorep .....)

autorep输出存储在文件ar.out中的示例:

awk '/insert_job/ {printf "%s %s ", $2, $4}; /date_conditions|condition/ {printf "%s\n", $2}' ar.out 
test_ujjal CMD 0

相关问题