*1 flash read test(*do_test1*) PASS
*2 xxxxxxxxxxx flash write test(*do_test2) FAIL ------>xxxxx
*1 flash read test(*do_test1*) PASS
*2 xxxxxxxxxxx flash write test(*do_test2) FAIL ------>xxxxx
I want pass and Fail to be aligned
if each line uses printf or echo to print, is there anyway to let them align?
Here is a solution but I'm sure there is an easier way to do this I missed:
awk '
FNR==NR{ m=index($0, "FAIL"); max=m>max?m:max; next }
/PASS/ {
i=index($0, "PASS");
if(i>max) $0=substr($0,1,max-1) substr($0,i)
else
$0=sprintf("%s%"max-i"s%s",substr($0,1,i-1), "", substr($0,i))
}1' infile infile
Supports this type of infile:
1 flash read test(*do_test1*) PASS
1 flash read test(*do_test1*) PASS
1 flash read test(*do_test1*) PASS
*2 xxxxxxxxxxx flash write test(*do_test2) FAIL ------>xxxxx
awk '/ PASS/{i=index($0, " PASS")}
/ FAIL/{i=index($0, " FAIL")}
{a[++n]=substr($0, 0, i-1);
b[n]=substr($0, i);
if(max < i-1) max = i-1}
END {for(i=1; i<=n; i++) printf "%-*s%s\n", max, a, b}' file
1 Like
Chubler_XL made a reasonable guess at what may be wanted. The specification leaves a lot to be desired:
- Are there always only two lines?
- Is the FAIL always on the 2nd line? Or, if there can be more than two lines, always on the last line?
- Is the FAIL always further to the right on a line than all occurrences of PASS?
- Will there every be any text following PASS?
- Will there ever be more than one FAIL line?
- How big can the file we're processing be?
- Will there always be a FAIL line?
if each line uses printf or echo to print, is there anyway to let them align?
Yes. Did you look at Chubler_XL's or SriniShoo's printf commands?
If their code didn't work, maybe we could try to fix it if you would answer the questions I asked three weeks ago...