Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK: find a character, delete character and rest of word 1

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
Say I have ....

423045.000N

and I want to find the "." and delete the rest of the word.

example:

cat 423045.000N | awk '{gsub(/\.+/,""); print}'

gives me --> 423045000N
but I want --> 423045
 
awk '{for(i=1;i<=NF;++i) sub(/\..*/,"",$i); print}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
...oh, but I have a slight wrinkle ...

same problem, but now I have multiple words that I have to run this though ...

I have ...
423045.000N 0772345.000N

I want ...
423045 0772345
 
Works for me:
echo 423045.000N 0772345.000N | awk '{for(i=1;i<=NF;++i)sub(/\..*/,"",$i); print}'
423045 0772345
 
...and it does for me now (my mistake)!!!

Thanks PHV !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top