当前位置: 动力学知识库 > 问答 > 编程问答 >

awk - GNU parallel with variable format printf

问题描述:

I have a bit of issue getting the correct output format with the code below. The output should look like this:

bb.pdf---------------color found

HIGHLY Rate.pdf------color found

etc...etc

I am getting:

bb.pdf---------------color found

HIGHLY Rate.pdf---------------color found

OK, so I am trying the get variable printf formatting with the use of the printf %s%*.*s%s format

where the *.* is set dynamically at run time. In the code below, in the line that begins with printf, if I set;

printf "%s%0.55s%s" $file_name $pad; gs -o - -sDEVICE............etc etc etc

then the code runs. That tells me I am close in getting this to work. The problem is I cannot get

the 0 and the $var_format to send their values to *.*, which will give me the variable nature of printf, i.e. printf "%s%0.$var_format%s". Appreciate anyone with an input.

A. Das

cat /cygdrive/i/PDF/$machine/results.csv | \

parallel -j200% --progress 'padlength=130;\

width=`echo {}| wc -c`;\

pad=$(printf '%0.1s' "-"{1..60});\

file_name=`echo -n {} | sed "s;.*/;;"`;\

var_format=$((padlength - width - 11 ));\

printf "%s%*.*s%s" $file_name 0 $var_format $pad ;gs -o - -sDEVICE=inkcov {} 2>/dev/null | \

awk "/CMYK OK$/ {if (\$1>0 || \$2>0 || \$3>0) {print \"------------------------------\

color found\"; exit;} } \

END {print \"\" }";' >> /cygdrive/i/PDF/$machine/color_report_summary.txt

网友答案:

Exmple on how to use printf with awk

cat file
bb.pdf
HIGHLY Rate.pdf


awk '{printf "%-30s %s\n", $0,var}' var="color found" file
bb.pdf                         color found
HIGHLY Rate.pdf                color found

-30 tells that first filed have a space of 30 characters and is left adjusted.
You need to set sufficient space for the longest field one.

分享给朋友:
您可能感兴趣的文章:
随机阅读: