Programming :: Replacing Numbers In Bash Scripts?

May 25, 2010

I have lines in some files that look exactly as below, and the line numbers they occur in are always the same. (Lines 136-139)

W 0.00000000 0.00000000 2.00000000
W 0.50000000 0.50000000 2.50000000
W 0.00000000 0.00000000 3.00000000

[code]...

View 1 Replies


ADVERTISEMENT

Programming :: Bash Rounding Up Numbers With Printf

Feb 2, 2010

For eg: $NUMBEROFPASSES=6.19 to round up I use NUMBEROFPASSES=$(printf %.0f $NUMBEROFPASSES) What I need to do is round up from eg: 6.10 to be 7 and if lower than 6.10 round down to 6

View 5 Replies View Related

Programming :: Random Float Numbers In BASH

Mar 27, 2011

I'm learning shell scripting using bash and I want to generate 4 floating point number with 5 decimal places and write them to a file and a variable. I've done all this except the $RAMDOM enviroment variable does not generate a float number but a integrer.

[code]...

View 4 Replies View Related

Programming :: Bash - Test If First 2 Characters In A Filename Are Numbers?

Oct 21, 2010

I have a directory with files like this:

Code:

And what I'd like is to have the files renamed like this:

Code:

How could I code it so that it removes the numerical part of the filename (at the beginning), even with different patterns (like the 01 - artist vs the 01-artist)?

View 8 Replies View Related

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

General :: Replacing A Numeric String With A Sequence Of Numbers?

Jun 21, 2009

I have a text file with content that look like this..

Code:
1,3927,"AIS"
1,6928,"AIS"

[code]...

View 13 Replies View Related

Programming :: Create Inverted Files To Associate Files To Numbers ( Numbers Being The Index Of My Paths )?

Apr 4, 2011

am writing a small search program for my class. I have decided to use indexing for my program. Ive researched online about indexing and how search engines do it. If im gonno do that I need to create inverted files to associate files to numbers ( numbers being the index of my paths ) . Now I was wondering what would be the best way to create an inverted file ? I was going to create sql tables using mysql api in C but then again there is no array data type or vectors to store few numbers in a single column in mysql and it is not advised to use Enum or SET

View 14 Replies View Related

General :: Replacing Empty Values In Bash?

Mar 11, 2011

I'm executing the below bash script, but when the m variable doesn't get any value it becomes empty. I don't want that.

Code:
for i in "$@"
do
m=$(grep TOTAL_MAPS $i | awk '{ print $2}');
totalmaps+="<string>"$m"</string>"

[Code]....

View 6 Replies View Related

General :: If ... Elseif ... Else BASH Ladder - Take In Two Numbers And Add Them

Nov 16, 2010

Our assignment is to take in two numbers and add them. While the inputs will always be numbers, we are to inform the user if they are doing it wrong. My code:

[Code]....

The code worked fine before I tried to idiot-proof it. I'll probably end up nesting the if statements checking if the first two inputs are not null, but I'm more annoyed at why the script isn't working.

View 3 Replies View Related

Software :: Bash Input Control - Different Numbers ?

Mar 18, 2011

I'm making an bash script.

As input you can input different numbers from 1 to 3.

Depending from the input a text shows up.

View 2 Replies View Related

Ubuntu :: Bash Script - For Loop - Replacing Strings?

Aug 16, 2011

I'm not overly great with bash scripting. I do more batch file stuff for Windows than anything else but I'm trying to branch out a bit. (Frankly, I'd love to do this in Ruby but I'm not there yet...) Maybe I'm not using the correct terminology and that's why my searches are coming up useless...

Anyway, I have a script that does some work with HandBrake. Although it deals with HandBrake, I think the issue is not with HandBrake itself. The issue: I had a simpler script which worked fine but it would give me an MP4 with a file name of: Some Movie Name.iso.mp4 and it would still play but I wanted to get rid of the .iso in the file name. I also wanted to drop it into another directory during the encoding. That's why you see a $source & a $destination variable.

handbrake.sh
Code:
#!/bin/bash
source=/media/data/movies
destination=/media/data/movies/mp4s

[Code]...

View 7 Replies View Related

General :: Parsing Columns In Bash / Extract The First Set Of Numbers And Get Them To Appear Only Once?

Sep 28, 2009

as a result of a find command, i have

852065 72: /bin/gunzip
852065 72: /bin/gzip
852065 72: /bin/zcat

(the first column is inode number and the second is size if you're curious)

I want to be able to format it in a way such that:
852065 72:
/bin/gunzip
/bin/gzip
/bin/zcat

I know I can get the bottom half using awk- but I can't figure out how to extract the first set of numbers and get them to appear only once

View 9 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

General :: Bash + Reading Values (numbers) From A File And Storing Them Into An Array?

Nov 4, 2010

I have to read a couple of numbers from a random.txt file. In this .txt file there are random numbers. They are separated by a space. Example if you opened test.txt:

test.txt :1 6 1 3 6 8 10 2 4

I would like to read those numbers using CAT and store them into an array:

numlen=${#num[*]} - (must be like this because it is a part of a larger program)

View 5 Replies View Related

Programming :: Replacing String Using Awk?

Jan 19, 2010

i have a string of information displayed in this way :

Code:
John:king:20:34:60
what i am tring to do is to read in input which is given by the user and change it to the

[code]....

View 3 Replies View Related

Programming :: Replacing The Last Digit?

Jun 23, 2010

i am trying to replace the last digit in the ip address(25) with 47 using following:Quote:echo 192.168.0.25|sed -r s/([0-9]*.[0-9]*.[0-9]*)/47/g'but not able so far, was wondering if you can help, so i can find my mistake.

View 6 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 :: Sum The Numbers Between And Including A And B?

Feb 11, 2010

write a script in bash or shell to add the numbers between and including two numbers

View 3 Replies View Related

Programming :: Prevent Sed From Replacing With Newline

Nov 28, 2009

I'm writing a script to replace some text that exists in about 50 .lex, .y, and .cc source code files, sometimes more than once in a file. Sometimes the text is in a multiline C comment, and other times it's within a multiline C string.

I use sed to grab the start and end of each line and wrap the new text in the old whitespace and/or quotes and Problem is, sed is changing the characters into a newline.

Is there a way to tell sed to not process escape sequences? I tried using several variations of

Code:

To no avail. Or could it be bash?

I would give up on the script and do it by hand, but this is something that I must do from time to time.

Here's the function which replaces the first occurrence found:

Code:

When $post is printed by echo, it shows the - but by the time the file is on disk, it becomes a newline. What should I do to ensure that it stays as the characters ?

View 4 Replies View Related

Programming :: Replacing Space Characters W/ ' ' Using Tr?

Jun 16, 2010

Okay, so I have a .txt file, LL.txt; here is its contents:

Code:
/mnt/sda1/Music/Lydia Lunch/Honeymoon In Red
/mnt/sda1/Music/Lydia Lunch/Honeymoon In Red

[code]....

View 9 Replies View Related

Programming :: Perl - Interpreter For Fib Numbers

Apr 1, 2010

As some of you know that I am new to this forum. I have another problem that I got stuck on. I have this file called "Fib.rbb" and my instructor told us to write an interpreter program by using Fib.rbb.

"You are to write an interpreter in Perl for Rongs Basic Basic (RBB) as explained in class. The BNF description for RBB and a test file called Fib.rbb are part of the RBB.zip file which is available in the Course Documents folder on blackboard. If you call your interpreter myIntp.pl, you would execute the program via perl myIntp.pl Fib.rbb

Code: Print "A few Fibonacci numbers:"

View 3 Replies View Related

Programming :: Code To Add 5 Numbers In Assembly?

Mar 28, 2011

Looking for code to add 5 numbers in assembly? I want to use array for input of those 5 numbers. No problem if the output is 1 digit(0....9).

View 3 Replies View Related

Programming :: Extract 2 Numbers From A Same File?

Dec 22, 2010

I am trying to extract 2 numbers from a same file and my goal is to print them both in another file, on the same line, separated with a space. I have to do that for 20 files and I would like to have therefore 20 lines like this in the output file. It would look like this :

Quote:

number1_file1 number2_file1
number1_file2 number2_file2
...
...
number_1_file20 number2_file20

So far, I did only extract one number and got an output file like this :

Quote:

number1_file1
number1_file2
...
...
number1_file20

And I did this by running a bash script with the following content :

Code:

#!/bin/bash
ls execution$1$2*.* | while read filename
do
cat $filename | grep -e "Total aborts:" | cut -d " " -f3 >> abort$1$2.dat
done

$1 and $2 are just strings to identify the different files I want to consider in this loop. This script works well to extract a number which is the 3rd field of a line starting with "Total aborts:".Now, how could I change this script to do what I mentioned above (i.e. extracting two numbers from two different lines) ? The second number is the 3rd field of a line starting with "Total throughput:"

View 7 Replies View Related

Programming :: Date Subtraction Using Numbers

Nov 15, 2010

I want the get the date of the oldest log in this directory and compare it with current date.Time of the each log can be seen before ".Z" prefix.I have written the following piece of code. However, it is not working for the following case:

LOGDAY=20101129
TODAY= 20101201

Difference is 72, which is not correct, since these are dates.

View 11 Replies View Related

Programming :: Generating Prime Numbers In C?

Mar 9, 2011

I'm trying to write a program that generates a random number and then tells if it is prime or not. I have doe some research about how to calculate prime and random numbers but I'm still having trouble. I don't really get how to calculate a prime number. I know a prime number is a number that is divisible by 1 and and itself. how to calculate a prime number in C?

View 10 Replies View Related

Programming :: Matching Numbers With Nawk

May 11, 2011

I am struggling to understand why nawk matches values that are either 1 or 2 digits in length, but not 100 (3 digits).

Am I missing something obvious ? Should I use substr to remove the % ?

I am sure it's something to do with character and string matching behaviour with nawk.

Code:

View 9 Replies View Related

Programming :: Storing Numbers In QByteArray?

Dec 15, 2010

I have a program that sends QByteArray datagrams over a udp socket. I would like to have 4 bytes of the datagram that contain a 32 bit integer. When saving numbers to the QByteArray, I have tried the static function number(int) and member function setNum(int), but they convert the integer to its decimal string representation and save that in the byte array. So if the number were 10, it takes 2 bytes, if it were 10,000,000 it takes 8 bytes. This wastes space, and makes it more difficult to get the number when it is packed with a few other pieces of data in the same datagram. Is there a standard way of doing this in Qt?

View 1 Replies View Related

Programming :: Replacing Set Of Characters In A Specific Line Using Sed Or Awk?

Dec 29, 2010

I would like to replace 'xxxx' with 'yyyy' which is in a file xyz.csproj not sure of what 'xxxx' is, it can be 3055, 4056, 7089 etc. I know it always appears at line # 5 and at character 50.

<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Windows.Forms" />

[code]....

View 14 Replies View Related

Programming :: Replacing Text With A Http Link With Sed?

Dec 10, 2010

Been at this all morning and fail on every attempt.

I have a file called sitemapindex.xml

Its contents just are names of the other sitemaps. Google gets pissy because it isn't in a http:// format.

So, I need "<loc>sitemap-c1mediawiki-............</loc>" to be replaced with "<loc>http://domain.tld/sitemap-c1mediawiki-............</loc>".

Here's the expression I've been trying:

find /path/to/site/sitemap-index-c1mediawiki* -type f | xargs sed -i 's/[<loc>sitemap]/[<loc>http://domain.tld/]/'

It fails.

I've tried with and without brackets.

View 4 Replies View Related

Programming :: Allowing Export To Take Numbers As Variables?

Jan 26, 2011

I'm playing around with some shell scripting and I've got a directory call CS005 and I'm trying to write a script to I can locate to the directory really quick and easy.

export CS005DIR=/home/stud/0/043234/CS005

Now I get this error

CS005DIR=/home/stud/0/043234/CS005 No such file or directory.

This is because I've got numerical values within my variable.

Is there a way to allow numbers for variable names?

View 3 Replies View Related







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