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
Why not a segmentation fault?? lagigliaivan High Level Programming 22 05-21-2008 11:07 AM
File Transfer that is not so trivial I guess Legend986 UNIX for Dummies Questions & Answers 1 03-07-2008 05:40 AM
Segment Fault zhshqzyc High Level Programming 9 04-07-2006 11:47 AM
memory fault iwbasts High Level Programming 1 03-21-2006 04:15 AM
Need help for a simple script (i guess so...) HowardIsHigh UNIX for Dummies Questions & Answers 1 07-01-2003 10:19 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-24-2007
maskot maskot is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 20
guess the fault :)

I really cant understand whats wrong with this:

File looks like this:
55 11

Code:
cost=30
a= cut -c9-12 File
let a=${a}+${cost}
echo $a

The answer echo should echo 11+30(cost) however the output looks like this:
11
30

And also is there anyway to grep $2 without awk? or maybe awk grep $2?
wouldnt mind get this loop to work instead
for i in cut -c1-12 awk ' $2 ~ "^[0-9]" && $2 > 0 {$2='$i'} ' 5 `
  #2 (permalink)  
Old 05-24-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Are you trying to sum second field from file with value in cost?
Code:
cost=30
a=$(( cost + $( cut -d" " -f2 file) ))
echo $a
  #3 (permalink)  
Old 05-24-2007
maskot maskot is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 20
Thank you

It does work if the f2 is actually on field 2 but its is on field 23 so to speak.
File do look like this:
Col10 51 Col23 11


Col10=10 space Col 23=23spaces
  #4 (permalink)  
Old 05-24-2007
maskot maskot is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 20
Got it to work

Thank you for the help mate.

Got it to work like this:
cost=30
a=$(( cost + $( cut -c23-26 5) ))
echo $a
  #5 (permalink)  
Old 05-24-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by maskot
It does work if the f2 is actually on field 2 but its is on field 23 so to speak.
File do look like this:
Col10 51 Col23 11


Col10=10 space Col 23=23spaces
If you have only two fields separated by spaces, then use awk
Code:
a=$(( cost + $( awk ' { print $2 } ' file) ))
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 11:00 PM.


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