Home > Mobile >  Grep output on seperate line
Grep output on seperate line

Time:12-11

I have the below script:

#!/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

i get the output

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

when i modify the script to:

   #!/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
  

I get the output as:

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

What i am looking for is if i can get the output like below:

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

EDIT:

below is the autorep output

 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

CodePudding user response:

Assuming your autorep output is:

/* ----------------- 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

The following awk might work for you:

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

Example with autorep output stored in file ar.out:

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