Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print first line unconditionally

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL
hello,

I'd like to get whole 1st line (header line, makred in blue) printf in each iteration in below for loop.

What I get now is:

Code:
# cat inputtest
===> hostA: transfer 16/09/2016,00:00:01 - 16/09/2016,23:59:59          5        42.64
===> hostB: transfer 16/09/2016,00:00:01 - 16/09/2016,23:59:59          3        65.24
===> hostA: transfer 17/09/2016,00:00:01 - 17/09/2016,23:59:59          7        22.54
===> hostB: transfer 17/09/2016,00:00:01 - 17/09/2016,23:59:59          7        36.34
# for a in hostA hostB;do echo "---==== $a ====---";{ echo "[COLOR=#3465A4]date files size[/color]";grep $a: inputtest|tr -s ' '; } |awk -F"[ |,]" '{printf "%+11s %+10s %+10s\n",$4,$(NF-1),$NF}';echo;done
---==== hostA ====---
                 files       size
 16/09/2016          5      42.64
 17/09/2016          7      22.54

---==== hostB ====---
                 files       size
 16/09/2016          3      65.24
 17/09/2016          7      36.34

#

what to check in the awk in the loop to achieve this?:

Code:
---==== hostA ====---
       date      files       size
 16/09/2016          5      42.64
 17/09/2016          7      22.54

---==== hostB ====---
       date      files       size
 16/09/2016          3      65.24
 17/09/2016          7      36.34


 
Update: I've figured it out

Code:
# for a in hostA hostB;do echo "---==== $a ====---";printf "%+11s %+10s %+10s\n" date files size;grep $a: inputtest|tr -s ' '|awk -F"[ |,]" '{printf "%+11s %+10s %+10s\n",$4,$(NF-1),$NF}';echo;done
---==== hostA ====---
       date      files       size
 16/09/2016          5      42.64
 17/09/2016          7      22.54

---==== hostB ====---
       date      files       size
 16/09/2016          3      65.24
 17/09/2016          7      36.34
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top