Grep commands & format

I have these grep commands and need to put them next each other (in horizontal layout).

cat /tmp/dsmc.out |grep Done
cat /tmp/dsmc.out |grep "Elapsed processing time:"
cat /tmp/dsmc.out |grep "Client date/time:"
cat /tmp/dsmc.out |grep "Total number of bytes transferred:"

so that it shows as:

Done "Elapsed processing time:" "Client date/time:" "Total number of bytes transferred:".

Please advise.

Try the

paste

command to place the output horizontally

1 Like

You mean the outputs? also dont use cat when you are using grep/sed/awk they are capable of reading the file..

1 Like

Sorry, how do you use

paste

in this case?

Try:

grep -e "Done" -e "Elapsed processing time:" -e "Client date/time:" -e "Total number of bytes transferred:" /tmp/dsmc.out | paste - - - -
1 Like

Be careful: different from using 4 grep s in a sequence, using one grep with 4 expressions does not guarantee the order of output elements that the requestor perhaps wants.

1 Like

This file contains command output and then typically the order within a record will be maintained. The alternative would be to fill 4 separate files with 4 separate greps and then paste those files. But either way the correct presentation of those fields needs those 4 fields needs to be present exactly once per record, then either method should work.

Otherwise we would need to create an script that does this, with awk for example. We can make it ever more complex, but if a simple solution works in practice, then why not use that instead? That is why I asked the OP to try and see if it works. He can easily verify if it renders the desired result..

1 Like