The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk script to calculate total appsguy616 Shell Programming and Scripting 2 11-25-2008 11:21 AM
Awk help needed to calculate total senthilkumar_ak Shell Programming and Scripting 7 08-22-2008 12:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2009
TehOne TehOne is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 55
Calculate total sum from a file

The file content is dynamic and using this format:

Code:
name1 number1
name2 number2
name3 number3
name4 number4
....................
Need a smooth way to calculate the sum of all the numbers in that file (number1 + number2 + number3 + number4........ = total )
  #2 (permalink)  
Old 05-27-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
Oh thats an easy one. There is also 'bc' but that would be for really hard core math, and then there is "let".. but dont worry with those.. you can just use awk.

Code:
-bash-3.2$ cat test.txt
one 1
two 2
three 3
four 4
five 5
six 6
seven 7
eight 8
nine 9
ten 10

-bash-3.2$ awk '{count += $2;} END { print count; }' test.txt
55
  #3 (permalink)  
Old 05-27-2009
TehOne TehOne is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 55
Works like a harm, thanks!
  #4 (permalink)  
Old 05-27-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
No problem!
  #5 (permalink)  
Old 05-27-2009
rakesh_pagadala rakesh_pagadala is offline
Registered User
  
 

Join Date: May 2009
Location: hyderabad
Posts: 20
to get the column by comparing a word

Hi all,
I am new to this forums so was not able to find to post new forums hence i posted in the already existing form please help me with the below requirement

I have a requirement as below I want to grep xyz and get the result domain name as "unix.com"

3.209.12.09 xyz xyz.unix.com

Last edited by rakesh_pagadala; 05-27-2009 at 06:18 PM..
  #6 (permalink)  
Old 05-27-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 527
Quote:
Originally Posted by rakesh_pagadala View Post
...
I have a requirement as below I want to grep xyz and get the result domain name as "unix.com"

3.209.12.09 xyz xyz.unix.com
Something like this:

Code:
$
$ cat input.txt
3.209.12.09 xyz xyz.unix.com
$
$ awk '{sub("xyz.","",$3); print $3}' input.txt
unix.com
$
tyler_durden
  #7 (permalink)  
Old 05-27-2009
rakesh_pagadala rakesh_pagadala is offline
Registered User
  
 

Join Date: May 2009
Location: hyderabad
Posts: 20
Quote:
Originally Posted by durden_tyler View Post
Something like this:

Code:
$
$ cat input.txt
3.209.12.09 xyz xyz.unix.com
$
$ awk '{sub("xyz.","",$3); print $3}' input.txt
unix.com
$
tyler_durden
Thanks for your help !!! But need some more of your help

There is an another clause over here which i found just now ... xyz.unix.com can come any where in the line it need not be at $3 every time
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0