Register
It is currently Sun Dec 21, 2014 11:34 am

Awk with gsub


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Feb 14, 2010 11:39 pm   

Joined: Sun Feb 14, 2010 11:30 pm
Posts: 1
Can someone tell why ;1 is mandatory in following awk with gsub expression.
awk '{print $2}' tmp | awk '{gsub (/.*-.*-/, "")};1'

there is a file with content:
[root@puvmlx002 opt]# cat tmp
nilesh 18-05-1984
akshay 12-23-1983
urmila 13-23-1983
aparna 23-12-1982

The objective is to extract only the birth years and print them in a column.
i did the following statement:
[root@puvmlx002 opt]# awk '{print $2}' tmp | awk '{gsub (/.*-.*-/, "")};1'
1984
1983
1983
1982

Any help is appreciated.


Top
 Profile  
 PostPosted: Mon Feb 15, 2010 2:36 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
Here is BashScripts, not AwkScripts!

A pipe from/to awk is useless and non sense, you should be able to do it straight.

You could also use lighter sed command.

Here's Bash use:
Code:
while read line; do echo "${line##*-}"; done < tmp


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP