×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

print first line unconditionally

print first line unconditionally

print first line unconditionally

(OP)
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 --> shell

# 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 "date files size";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 --> output

---==== 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 


RE: print first line unconditionally

(OP)
Update: I've figured it out

CODE --> solution

# 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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close