1

The output of my shell script is as follows(please find the attached image)

workflow_Name1
Succeeded
Tue May 19 11:15:33 2015
workflow_Name2
Succeeded
Wed Jun 10 18:00:21 2015

I want this to be changed to

workflow_Name1 :-Succeeded :-Tue May 19 11:15:33 2015
workflow_Name2 :-Succeeded :-Wed Jun 10 18:00:21 2015

Following is the script I am using. Could you please let me know how to achieve this.

#!/bin/bash
# source $HOME/.bash_profile

output=/home/infaprd/cron/output.lst

sqlplus -s user/test@dev <<EOF >$output   # Capture output from SQL
set linesize 55 pages 500
spool output_temp.lst;
set head off;
select sysdate from dual;
set head on;
spool off;
EOF

for name in workflow_Name1 workflow_Name2; do
  pmcmd getworkflowdetails -Repository ${name}
done |
grep -e "Workflow:" -e "Workflow run status:" -e "End time:" | cut -d'[' -f2 | cut -d']' -f1 |

sed -e 's/ *$//' >> $output
mail -s "Output - `date '+%d-%m-%y'`" [email protected] <$output
0

1 Answer 1

2

You can do it using awk

awk '{getline a;getline b; if($0) printf "%-s\n", $0 " :-" a " :-" b}'

Output:

workflow_Name1 :-Succeeded :-Tue May 19 11:15:33 2015
workflow_Name2 :-Succeeded :-Wed Jun 10 18:00:21 2015

You can also use sed to accomplish this task:

sed 'N;N;s/\n/ :-/g'
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks Rakholiya, the sed's output is coming in a single line. How to print the second workflow in second line.
have a look at ideone.com/AJZANa. sed output is also the same as the awk output.
Thanks Rakholiya, Appreciate your help. The issue is, when writing to the file, its coming as single row. Otherwise in the command prompt, it comes as a two rows as expected. Any pointers.
@AkhilNarayananNair, when I am trying to redirect to output to a file using sed 'N;N;s/\n/ \:\-/g' inputfile > outputfile, output is coming in two separate lines for me.
I am sending the final file as an email. In the email it is a single line. Do I need to do any formatting for email.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.