Programming :: Bash Subtract Negative Number Using Bc

May 15, 2011

How can i get bc to subtract negative numbers?

View 10 Replies


ADVERTISEMENT

Programming :: Subtract Two Non-real (aka Decimal'd) Numbers Via Bash?

Apr 28, 2010

I just need to perform a simple operation of subtracting two numbers - that aren't whole numbers, i.e 200.56 - 67.24attempting to use expr i merely get "expr: non-numeric argument"

View 3 Replies View Related

Programming :: Bash: Printing The Line Number In Bash Script?

Feb 4, 2011

I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.

View 3 Replies View Related

General :: Bash - Subtract Contents Of One Textfile From Another

Jul 7, 2010

I have two text files on Linux. One contains a list of valid IDs. E.g:
abcd
efgh
ijkl
etc.

The other contains a list of invalid IDs. But, some of these also appear on the list of valid IDs, in this example "efgh":
mnop
qrst
efgh
etc.

How can I easily construct a text file that contains all the lines from the invalid list that do not appear in the valid list? That is, I want to end up with a text file that has:
mnop
qrst
etc.
I'd like either some Linux commandline magic of some clever Vim trickery.

View 3 Replies View Related

General :: How To Grep Negative Number In File?

Mar 4, 2010

I wanted to grep the line in a file starts with -1.000000e+00.

Tried grep "-1.000000e+00" *, got error "grep: invalid option --".
Neither of the following works:
grep "-1.000000e00" *
grep "1.000000e00" *

How do I grep a negative number with scientific notation?

View 3 Replies View Related

Programming :: Bash:Printing The Line Number In Script?

Feb 4, 2011

I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.

View 2 Replies View Related

Programming :: Counting The Number Of Exit Variables - Bash

Jul 1, 2010

Is there a way to count the number of errors- an exit variable $? from one function?

The output from the exit variable (either erroneous or correct (1) or (0)) is it possible to add the erroneous one ups?

View 3 Replies View Related

Programming :: Bash Script For Moving X Number Files From / Direct1 To / Direct2?

Jan 29, 2010

I have no Bash skills but Im badly in need of a script to move the first 20,000 or whatever number of files from a directory containing over 200,000 files to a new directory. The problem is that I cant access the directory because its so large so I want to break it into chunks, but keep the files in order if possible. If you know of a script to meet my needs, please post it. Otherwise Ill post my fumblings with Bash until I find the right way to fix my problem.

View 14 Replies View Related

Programming :: BASH Script Optimization For Testing Large Number Of Files

Sep 18, 2010

I want to move files from a $SOURCEDIR to a $DESTBASE/$DESTDIR. Under $DESTBASE there are many directories, and I need to test beforehand if a file from $SOURCEDIR already exists in any of them.

This is obviously extremely slow, and the real use case involves dozens of dirs and thousands of files. Creating a temporary "index" file for the find command (instead of running it every iteration) speeds it up a little, but it's still very clumsy.

View 14 Replies View Related

Programming :: Bash Script To Count Number Of Lines With A Specific Property7?

Aug 11, 2010

I would like to parse an input file in which there are two columns per each row. We want to see how many lines are duplicated where we define duplicate to be having the same second field and different first field. For instance if the input file looks like the following:

79874 13131
79873 12309
79820 13131

[code]...

View 10 Replies View Related

Programming :: How To Convert Negative Integer To Byte Array?

Oct 26, 2010

I need to convert an integer to a byte array of size 2 and vice versa. The code shown below works well for positive values but not for negative values. Also, using an array of size four makes the conversion works. However, I am limited to an array of size 2.

View 5 Replies View Related

Programming :: No While Loop Is AllowedThe Lecturer's Tip Was To Treat "-" As Negative And Not Hyphen?

Mar 25, 2010

I have a assignment relating to barcode reading.Let say i have to enter the 13 digit barcode with hyphen e.g "Enter barcode:123-46574-48847" using scanf.Once thats done how do i extract the values without the hyphene.g using printf "1234657448847". No arrays No strings and No function is allowed.No while loop is allowedThe lecturer's tip was to treat "-" as negative and not hyphen.

View 4 Replies View Related

Ubuntu :: Subtract Two Variables In Awk

Feb 11, 2011

Turns out I don't have bc in my Ubuntu distro and I can't install it. how to subtract two variables (BASH variables) from awk and set the result as another variable, e.g: finalvalue=`awk '{print $first - $second}'`

View 2 Replies View Related

General :: Bash Scripting - Grab First And Last Number?

Jan 13, 2011

I'm trying to get an output of a file in numeric order. Basically I need the starting number and the ending number in sed this into anther file. The test2.lis file I'm just awk'ing for the first row and if its out of order put it in order so I can grab the first and last numbers. I'm sure I can do this all in an array. The first sed command gets rid of blank lines and outputs it to a file. Then I head and tail for the first and last number then I want to sed those numbers into a file that exsist.

[code]...

The error I get is:

sed: -e expression #1, char 24: unterminated `s' command.

View 13 Replies View Related

General :: Extract Only Number In A Path In Bash?

Mar 17, 2011

I've these path:

Code:
xxx/yyy/zzz/0908/aaa/a.txt
xxx/yyy/zzz/0909/aaa/a.txt
xxx/yyy/zzz/0910/aaa/a.txt
fff/ggg/hhh/iii/jjj/0911/aaa/a.txt
fff/ggg/hhh/kkk/0912/aaa/a.txt

and I would like to extract only the number, so that I've get the result

Code:
0908
0909
0910
0911
0911

How can I do it in bash?

View 1 Replies View Related

General :: Breaking Iteration After A Given Number Of Iterations (bash)?

Jun 14, 2011

Take this block of pseudocode:

Code:
for i in $list; do
<some statements>
if i > 5
exit
<more statements>
done

That is, want to terminate the iteration just after 5 iterations. A first problem, is that list is a string and not a number. It's all I can say, except to keep reading bash monster manual.

View 8 Replies View Related

Software :: Bash Script To Run Commands For Specified Number Of Seconds?

Dec 2, 2009

I want to make a very simple bash script to run a command for a user-specified number of seconds and then kill it. The purpose is to limit the amount of time the program runs.Example in pusedocode:

Code:
#!/bin/bash
#$1 is the user input number of seconds

[code]...

View 14 Replies View Related

Ubuntu :: BASH Script - How To Stop Loading Files At Arbitrary Number

Aug 9, 2010

I have the following code in bash script:
Code:
#!/bin/bash
COUNT=1
# bash until loop
until [$COUNT -gt 2]; do
pq A$COUNT [Pemptus].pq &
let COUNT=COUNT+1
done

I did this because I'm that much of a Progress Quest geek that I wanted to have a huge group on the online server, so I decided to make a script that would open all the files for me rather than having me do it manually. I created some characters with the boring name of A1, A2, etc. When I ran the above script, it went into a continuous loop and I had to halt it, then run sudo killall pq.exe to eliminate the 500 or so Progress Quest windows that popped open. Anyway, what is wrong with my script that I can't seem to get it to stop loading files at an arbitrary number? I want to get this part finished before I make any more boring named characters.

View 1 Replies View Related

General :: Replacing Word Occurrence With An Increasing Number In A File Using Bash?

Aug 2, 2010

I have a file in the form below, and wish to replace each start line with an increasing number. So instead of:

Code:
start
content content
start
content content
start

[Code]....

After several searches and a bit of messing around, it's clear I'm missing something, so was wondering if anyone could offer any insight?

View 17 Replies View Related

Programming :: Bash Ctrl+c Tarp And Bash Read With Timeout?

Jan 24, 2010

simple bash code:

Code:
#!/bin/bash
trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c
echo "Press ctrl+c during 5 sec loop"
for ((i=0;i<5;i++)); do

[Code]...

How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!

View 10 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

Programming :: Run Multiple Bash And Php Scripts From A Bash Script?

Jul 25, 2011

I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.

Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?

View 5 Replies View Related

Programming :: Bash: Get Filename And Extension Using Bash?

Jan 9, 2010

I would like to get the filename (without extension) and the extension separately. The best solution I found so far is:

Let FILE="thefilenameofsomefilesfor_instance.txt"

Code:

NAME=`echo "$FILE" | cut -d'.' -f1`
EXTENSION=`echo "$FILE" | cut -d'.' -f2`

I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.

View 5 Replies View Related

Programming :: Get A Number Between Two Numbers?

Feb 1, 2010

I have some code that opens a directory and reads in the names of files which are e.g. 0001, 0002, 0003 up to 9999I need to get all these numbers and then generate a new number that is not one of these numbers already.here is my code to check the files in the directory

DIR *d;
struct dirent *dir;
int i = 0;

[code]....

View 11 Replies View Related

Programming :: How To Get A Unicode Number

Jul 7, 2011

But what is the easiest way to figure out the Unicode number of a character when you already have the character?

For instance, I pasted this character here from a PDF:

View 4 Replies View Related

Programming :: How To Get Number Of Cores Using C?

Apr 13, 2011

Anybody knows How can I get the number of cores of a machine?I know that I can use POPEN and get the stream of this:

Code:
grep -i 'processor' /proc/cpuinfo | wc -l
But, I think that a simple method to do this.

View 10 Replies View Related

Programming :: Get Random Number From -1 To 1 In C?

Mar 4, 2011

i want to generate random number in c programming from -1 to 1

View 1 Replies View Related

Ubuntu Installation :: 10.10 Wubi Upgrade Seems To Have Corrupted Bash / Error "invalid Magic Number"?

Jan 4, 2011

I tried the steps usually offered (modifying the grub.cfg file, replacing the wubildr files), it still wouldn't boot.

I booted in with the LiveCD to try to chroot into the environment and try running 'update-grub'. However, whenever I tried to chroot, it said it could not execute /bin/bash!

Trying to modify the grub commands manually (which originally gave the error: you need to load the kernal first), in the end said "invalid magic number"

There are some configuration things set in this installation I would like to not lose. Is it hopeless?

View 6 Replies View Related

Programming :: Grep For Exact Number 0?

Aug 6, 2010

1) I need to search a field value to check for exact 0. If the number is 0, it should throw error.

The line to be searched looks like as below. "Output Rows [1], Affected Rows [1], Applied Rows [1], Rejected Rows [0]"

Here I have to search whether the affected rows is 0. But the code below picks up other values also (lie 10, 20.. etc). How do we write to get an exact match for 0? Code: affected=`echo ${line} | cut -f6 -d" " `

affectedcount='echo ${affected} |grep 0 ` 2) Also, I need to check whether the rejected rows > 0
Code: rejected=`echo ${line} | cut -f12 -d" " `
rejectedcount='echo {rejected} |grep [1-9]`

3)Can we combine these two statements in a better way to get the desired results?

View 2 Replies View Related

Programming :: Check If The Variable Is A Number Or Not

Apr 30, 2011

I've created (as a homework) to create as many folders as told but I still need to check if the variable is a number or not :

Code: #!/bin/sh
echo "Veuillez saisir un nombre"; read nmbr
nmbrf=$nmbr
while [ $nmbrf -gt 0 ]
do mkdir -p "foo$nmbrf"
nmbrf=`expr $nmbrf - 1`
echo "$nmbrf"

how do I check that nmbr is a number or something else?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved