linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* simple awk question
@ 2003-10-20  8:17 urgrue
  2003-10-20 20:19 ` Chuck Campbell
  2003-10-20 21:09 ` Chuck Campbell
  0 siblings, 2 replies; 4+ messages in thread
From: urgrue @ 2003-10-20  8:17 UTC (permalink / raw)
  To: admin

how can i print all BUT the last field. ie something like:
echo one.two.three.four | awk -F "." '{print <all from $1 to $(NF-1)>}'
=one.two.three

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: simple awk question
  2003-10-20  8:17 simple awk question urgrue
@ 2003-10-20 20:19 ` Chuck Campbell
  2003-10-20 21:09 ` Chuck Campbell
  1 sibling, 0 replies; 4+ messages in thread
From: Chuck Campbell @ 2003-10-20 20:19 UTC (permalink / raw)
  To: urgrue; +Cc: admin

On Mon, Oct 20, 2003 at 11:17:58AM +0300, urgrue wrote:
> how can i print all BUT the last field. ie something like:
> echo one.two.three.four | awk -F "." '{print <all from $1 to $(NF-1)>}'
> =one.two.three

echo one.two.three.four | awk -F "." \
 '{for (i=1; i<NF-1 ;i++) {printf("%s.",$i)};printf("%s\n",$(NF-1))}'



-chuck
-- 
ACCEL Services, Inc.| Specialists in Gravity, Magnetics |  1(713)993-0671 ph.
 2401 Fountain View |   and Integrated Interpretation   |  1(713)993-0608 fax
     Suite 320      |                                   |
 Houston, TX, 77057 |          Chuck Campbell           | campbell@accelinc.com
                    |  President & Senior Geoscientist  |

     "Integration means more than having all the maps at the same scale!"

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: simple awk question
  2003-10-20  8:17 simple awk question urgrue
  2003-10-20 20:19 ` Chuck Campbell
@ 2003-10-20 21:09 ` Chuck Campbell
  2003-10-21 14:51   ` Chuck Campbell
  1 sibling, 1 reply; 4+ messages in thread
From: Chuck Campbell @ 2003-10-20 21:09 UTC (permalink / raw)
  To: urgrue; +Cc: admin

On Mon, Oct 20, 2003 at 11:17:58AM +0300, urgrue wrote:
> how can i print all BUT the last field. ie something like:
> echo one.two.three.four | awk -F "." '{print <all from $1 to $(NF-1)>}'
> =one.two.three

Sorry, I didn't test my first one.  Your syntax for calling awk was wrong,
and I blindly copied it when I put in my recipe.   

This:
echo one.two.three.four | awk -F "." \
 '{for (i=1; i<NF-1 ;i++) {printf("%s.",$i)};printf("%s\n",$(NF-1))}'

Should actually read:
echo one.two.three.four | awk -F. \
 '{for (i=1; i<NF-1 ;i++) {printf("%s.",$i)};printf("%s\n",$(NF-1))}'


Please note the -F flag difference in the awk command line.

-chuck


-- 
ACCEL Services, Inc.| Specialists in Gravity, Magnetics |  1(713)993-0671 ph.
 2401 Fountain View |   and Integrated Interpretation   |  1(713)993-0608 fax
     Suite 320      |                                   |
 Houston, TX, 77057 |          Chuck Campbell           | campbell@accelinc.com
                    |  President & Senior Geoscientist  |

     "Integration means more than having all the maps at the same scale!"

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: simple awk question
  2003-10-20 21:09 ` Chuck Campbell
@ 2003-10-21 14:51   ` Chuck Campbell
  0 siblings, 0 replies; 4+ messages in thread
From: Chuck Campbell @ 2003-10-21 14:51 UTC (permalink / raw)
  To: Chuck Campbell, urgrue, admin

On Mon, Oct 20, 2003 at 04:09:55PM -0500, Chuck Campbell wrote:
> On Mon, Oct 20, 2003 at 11:17:58AM +0300, urgrue wrote:
> > how can i print all BUT the last field. ie something like:
> > echo one.two.three.four | awk -F "." '{print <all from $1 to $(NF-1)>}'
> > =one.two.three
> 
> Sorry, I didn't test my first one.  Your syntax for calling awk was wrong,
> and I blindly copied it when I put in my recipe.   
> 
> This:
> echo one.two.three.four | awk -F "." \
>  '{for (i=1; i<NF-1 ;i++) {printf("%s.",$i)};printf("%s\n",$(NF-1))}'
> 
> Should actually read:
> echo one.two.three.four | awk -F. \
>  '{for (i=1; i<NF-1 ;i++) {printf("%s.",$i)};printf("%s\n",$(NF-1))}'
> 
> 
> Please note the -F flag difference in the awk command line.


It appears I was right, wrong and right again.  The original posting works
on all variants of gawk (gnu awk) and nawk I have available.

The second posting is required if you happen to be on Solaris, and are using
normal awk, however both work fine on Solaris using gawk or nawk.

Thanks to those who pointed out my error(s).

-chuck


-- 
ACCEL Services, Inc.| Specialists in Gravity, Magnetics |  1(713)993-0671 ph.
 2401 Fountain View |   and Integrated Interpretation   |  1(713)993-0608 fax
     Suite 320      |                                   |
 Houston, TX, 77057 |          Chuck Campbell           | campbell@accelinc.com
                    |  President & Senior Geoscientist  |

     "Integration means more than having all the maps at the same scale!"

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-21 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-20  8:17 simple awk question urgrue
2003-10-20 20:19 ` Chuck Campbell
2003-10-20 21:09 ` Chuck Campbell
2003-10-21 14:51   ` Chuck Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).