guess the fault :)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting guess the fault :)
# 1  
Old 05-24-2007
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 Smilie
for i in cut -c1-12 awk ' $2 ~ "^[0-9]" && $2 > 0 {$2='$i'} ' 5 `
Smilie
# 2  
Old 05-24-2007
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  
Old 05-24-2007
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  
Old 05-24-2007
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  
Old 05-24-2007
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) ))

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies

2. Homework & Coursework Questions

Bash Script for Dice Game; Issue with if...else loop to verify user guess is within range

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have written a script for a dice game that: (1) tells user that each of the 2 die are 6 sided (Spots=6); (2)... (3 Replies)
Discussion started by: LaurenRose
3 Replies

3. Homework & Coursework Questions

Segmentation Fault

this is a network programming code to run a rock paper scissors in a client and server. I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault. -the segmentation fault is fixed Current problem -Also... (3 Replies)
Discussion started by: femchi
3 Replies

4. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

5. Shell Programming and Scripting

Give user 5 chances to guess my favorite color

I wrote a script to give a user 5 guesses on what is my favorite color but I it doesn't work. I've only been scripting for a couple weeks and need some help it seems simple but how do I give the user 5 guesses? (3 Replies)
Discussion started by: noob
3 Replies

6. Ubuntu

Stack overflow i guess while insmod

I have built kernel 2.6.35 on my Ubuntu system with some specific requirement. I also built some app defined module with the same kernel. I booted up the built version and I find it did not work properly as there is some gui and other modules missing problem. But the system booted up and I did... (0 Replies)
Discussion started by: sunilsukumar4u
0 Replies

7. UNIX for Dummies Questions & Answers

File Transfer that is not so trivial I guess

I have three computers A, B and C. To login to B and C I should use A because it has a SSH key. I don't have any other way of accessing these two computers. Now, if I need to transfer a file between B and C, I am unable to find a way that would work... because I don't know how to authenticate... (1 Reply)
Discussion started by: Legend986
1 Replies

8. UNIX for Dummies Questions & Answers

Need help for a simple script (i guess so...)

Hi all! here is a sample of the file i am working on : $ cat toto.txt $20030613150250:Flux:ASS_IARD 20030613150250:Nombre d enregistrements Ecrits :27 20030613150250:Flux:ASS_TIER 20030613150250:Nombre d enregistrements Ecrits :27 20030613150251:Flux:ASS_PERS 20030613150251:Nombre d... (1 Reply)
Discussion started by: HowardIsHigh
1 Replies
Login or Register to Ask a Question