I know that by typing awk '{print $1, $2}' testfile will insert ONE tiny space
between the $1 and the $2 fields. However, I need more space between the $1
and the $2 than the above program is giving. I've even tried:
awk '{print $1, $2}' testfile and Unix still prints ONE space
between.
What am I doing wrong? Can a tab be inserted?
Thanks in advance.
--
Views expressed are personal and not necessarily shared by my employer.
You could set the output field separator to TAB.
awk '
BEGIN {OFS="\t"}
{print $1,$2}
' testfile
but this would mean all fields would be TAB separated.
regards
Martin
Try
awk '{print $1 "\t" $2}' testfile
You don't have to use a list: use the concatenation "operator" instead!
Chris Thompson
Email: cet1 [at] cam.ac.uk
> How do I insert a tab between two print fields in awk?
>
> I know that by typing awk '{print $1, $2}' testfile will insert ONE tiny space
> between the $1 and the $2 fields. However, I need more space between the $1
> and the $2 than the above program is giving. I've even tried:
>
> awk '{print $1, $2}' testfile and Unix still prints ONE space
> between.
>
> What am I doing wrong? Can a tab be inserted?
>
> Thanks in advance.
Try this
awk '{printf("%s<tab>%s\n", $1,$2)}
awk '{printf("%s\t%s\n", $1, $2)}'
Alternatively (and somewhat more simply, in this case):
awk '{print $1 "\t" $2}' testfile
note that there are no commas in this, this utilizes the string pasting
capability of awk.
Chuck Demas
Needham, Mass.
--
Eat Healthy | _ _ | Nothing would be done at all,
Stay Fit | @ @ | If a man waited to do it so well,
Die Anyway | v | That no one could find fault with it.
de...@tiac.net | \___/ | http://www.tiac.net/users/demas
For completeness' sake:
awk '{OFS="\t"; print $1,$2}' testfile
Christian
--
Christian Bauernfeind
Not speaking for Siemens
Not even working for IBM
e-mail: v2ba...@fishkill.ibm.com