# AwK printf question

**URL:** <https://community.unix.com/t/awk-printf-question/165154>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [September 14, 2006, 3:46pm UTC](https://community.unix.com/t/awk-printf-question/165154 "2006-09-14T15:46:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![whatisthis](https://community.unix.com/user_avatar/community.unix.com/whatisthis/32/129_2.png) [@whatisthis](https://community.unix.com/u/whatisthis)\
**Post date:** [September 14, 2006, 3:46pm UTC](https://community.unix.com/t/awk-printf-question/165154/1 "2006-09-14T15:46:22Z")

</div>

Hi,  
Does anyone know a easy way to printf $3,$4, ... all the way to the last field in the file? I will need to modify $1 and $2 and then printf modified $1 and $2 and the rest of the fields(which are not changed).  
I know I can use NF as the total number of field.  
Do I use a for next statement to loop through?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![anbu23](https://community.unix.com/user_avatar/community.unix.com/anbu23/32/351_2.png) [@anbu23](https://community.unix.com/u/anbu23)\
**Post date:** [September 14, 2006, 4:07pm UTC](https://community.unix.com/t/awk-printf-question/165154/2 "2006-09-14T16:07:52Z")

</div>

$1="xxxx"  
$2="yyyy"  
#if you want to print the whole line then do this  
print $0

---

<div class="post-metadata">

**Author:** ![whatisthis](https://community.unix.com/user_avatar/community.unix.com/whatisthis/32/129_2.png) [@whatisthis](https://community.unix.com/u/whatisthis)\
**Post date:** [September 14, 2006, 4:19pm UTC](https://community.unix.com/t/awk-printf-question/165154/3 "2006-09-14T16:19:00Z")

</div>

Thank you for your reply.  
The things is everytime the file that passed to awk is different.  
So I don't know the exact number of columns.  
But I only modify $1,$2. There might be over 10 fields after that.  
It's really $0 - $1 - $2.  
I need to write out any fields after $1 and $2.

Any hint?

---

<div class="post-metadata">

**Author:** ![anbu23](https://community.unix.com/user_avatar/community.unix.com/anbu23/32/351_2.png) [@anbu23](https://community.unix.com/u/anbu23)\
**Post date:** [September 14, 2006, 4:39pm UTC](https://community.unix.com/t/awk-printf-question/165154/4 "2006-09-14T16:39:28Z")

</div>

use for loop to do that

---

<div class="post-metadata">

**Author:** ![strike-2](https://community.unix.com/user_avatar/community.unix.com/strike-2/32/3910_2.png) [@strike-2](https://community.unix.com/u/strike-2)\
**Post date:** [December 10, 2007, 12:17pm UTC](https://community.unix.com/t/awk-printf-question/165154/5 "2007-12-10T12:17:10Z")

</div>

I know it's been over a year, but maybe someone else will benefit from this.  
If you want to print everything but a number of fields, set them to "" (null)

So, to print everything past $2, type:  
awk '{ $1=""; $2=""; print $0}' foo.log

This can be shortened to:  
awk '{ $1=$2=""; print $0}' foo.log

Be sure never to set $0 to null, because that will nuke your entire string.:o
