Issues formatting output of two commands in a single line.

I wish to generate output of two commands in the same line separated by a single white-space.

Below is my command and output in the same line.

ls -ltr fname1.out | awk '{$2=$4=$5=x; print}' | tr '\n' '\t' | tr -s ' '; cksum<fname1.out | cut -d' ' -f1

Output:

-rw-r--r--. root Aug 26 16:57 fname1.out        4294967295

The issue is that there is a tab space /t between the first and second command's output instead of having a single white-space i.e between

fname1.out        4294967295

Need suggestions to get equal single white spacing between all output elements.

calculate cksum first and assign it to a variable, then print that variable in the awk statement.

I'm using the above command in ansible shell module and would like to get this to work without involving variables... is that possible ?

ls will change the time column format depending on the age of the file eg:

-rw-r--r--  1 root root 89 Aug 29 12:08 booking
-rw-r--r--  1 root bin   0 Oct 21  2016 basic.log

do you want this in your output. If you want a consistent date and time then perhaps use find like this:

find fname1.out -printf "%M %u %TY-%Tm-%Td %TH:%TM %f $(cksum<fname1.out | cut -d' ' -f1)\n"

Result:

-rw-r--r-- root 2018-08-05 11:48 fname1.out 1187560795
3 Likes

Can I get the find to print the absolute path of the file like so : find /app/logs/fname1.out -printf "%M %u %TY-%Tm-%Td %TH:%TM %f $(cksum<fname1.out | cut -d' ' -f1)\n"

Desired Output:

-rw-r--r-- root 2018-08-05 11:48  /app/logs/fname1.out 1187560795

yes use %h/%f instead of %f :

find /app/logs/fname1.out -printf "%M %u %TY-%Tm-%Td %TH:%TM %h/%f $(cksum<fname1.out | cut -d' ' -f1)\n"
1 Like

Works !! Thanks @Chubler_XL