General :: Reading Numbers From Text File And Storing In Array?

May 26, 2010

I'm writing a bash script where I read a text file (containing a column of numbers) and store each line in an array. There seem to be some problems with the whole thing however, but only for some files and not others. Here's what I do:

Code:
#!/bin/bash
file=time_notOk.txt ### The file with a column of numbers
i=0 ### Array counter
### Read the file

[Code]....

View 3 Replies


ADVERTISEMENT

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 :: Reading Text File Into An Array

Oct 20, 2010

I know that this is a really simple thing to do but I just can't figure it out. How do I read a text file into an array in C++?

View 3 Replies View Related

Programming :: Reading In A Outside Text File And Putting In The String On That Line Into A Char Array That Is Already Allocated?

Mar 29, 2011

Here is the issue. I am reading in a outside text file and putting in the string on that line into a char array that is already allocated.

Code:
int main(int argc, char *argv[])
{

[code]....

View 1 Replies View Related

General :: Bash: Calculating In Array And Storing Result In Array?

Dec 2, 2010

I have an array called arrayini which stores numbers. I want to take log to the base 2 of each of the numbers in that array and put it in file called result. I've used the following code to do it.

Code:

size=${#arrayini[@]}
for ((i=0;i<size;i++))
do
echo "scale = 12; l(${arrayini[$i]})/l(2)" | bc -l
done >result

It works fine but its taking pretty long to calculate since I've got about 230,000 items in the array. So I decided to store the result into an array hoping that it'd be faster. I tried the following code. arrayresult is where I try and store the result. The code doesn't work because of the second last line.

Code:

unset arrayresult
size=${#arrayini[@]}
for ((i=0;i<size;i++))
do
arrayresult[$i]="scale = 12; l(${arrayini[$i]})/l(2)" | bc -l
done >FILE2

There is a syntax error clearly.

View 6 Replies View Related

General :: Bash: Reading File Into Array?

Dec 2, 2010

I have a file named file.txt with the following contents

Code:

19 man
24 house
44 dyam
90 random

I want to read the file into array and store each line in each index. I've tried using the following code.

Code:

dataarray=($( < file.txt ))

It stores each word in each index rather than each line in each index.

View 3 Replies View Related

General :: Storing Array From Awk In Bash?

Nov 24, 2010

i'm using awk inside bash. i've got an array in awk called arrayinawk. everytime i call another awk command in bash i have to keep creating arrayinawk to work with it. is there anyway i can store arrayinawk in bash and just call the stored value next time i use awk?

View 14 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 :: Reading A File Of Data In An Array?

Feb 10, 2011

I have two files of data with different numbers of columns and rows. I want to read this two files in two arrays and then compare for example the second column of first data file with the third column of the other text file and if the difference between of two numbers is less than a threshold then the program print the information in the rows which fulfill this condition in the third text file. I have written below program but the problem is that it does not go through all rows of second file.

declare -a a
declare -a b
r=` awk '{n++} END {print n}' second.txt `
echo $r
awk '
{

[Code]....

Actually I have two data files one of them contains 44406 and the other one has 12066 rows and I want to check whether the difference between the components of two specific columns is less than a threshod but I have simplified it here. I had written this code and then I have realized that this code just goes through the number of rows as the same as the first.txt file and ignores the rest. I could not find the problem yet.

View 2 Replies View Related

CentOS 5 :: Tape Files Are Not Storing With Phone Numbers?

Mar 5, 2010

I installed oreka and can make succesfully call recordings. The problem i'm facing is when i record a call and check the details in database, localparty, remote party fields are storing with source and destination ip address not with there phone numbers.

View 1 Replies View Related

Programming :: Bash - Reading Csv Delimited File To Array And For Further Manipulation?

Jan 6, 2010

I am trying to do this:

1. Read csv delimited file line1 and store all values in array

2. Use the values stored in the array and replace values in other text file with them

3. read line2 in the cvs file and repeat the process

4. Do above for all lines in the cvs file

for example:

file1.cvs content:

text1,text2,text3,"text 4"
a1,a2,3,"a 4"

file.txt content:

some text $array1$ some text
some text $array2$ some text

1. read line 1 - text1,text2,text3,"text 4" put each value in array X[] lines that contain spaces in cvs will have double quotes

2. read x[1] and replace value $array1$ (in file.txt) with x[1]read x[2] and replace value $array2$ (in file.txt) with x[2] and so on

Can above be accomplished in BASH and how?

View 1 Replies View Related

Programming :: Reading File Permissions Into Bash Array For Processing

Dec 1, 2010

I would like to read unix file permissions into a bash array for processing but tbh I have no idea how to do this. Then I will check for each individual access right l, d, x etc.

View 11 Replies View Related

Programming :: Reading From Text File In Bash?

Nov 8, 2010

I need to Read a path of a file witch is written in Text file i used this

Code:

FILENAME=$1
while read line
do
echo $line
done < $FILENAME

it worked and showed me the Line witch was written in my file but now my problem is how am gonna use that line as a path i mean for example if am gonna execute a linux command on that file like dpkg -i /path/to/the/file how am gonna export it from The $Line variable and use it after the command.

View 14 Replies View Related

General :: Getting Numbers From A Line Of Text?

May 10, 2010

I'm working with a rather large file of data taking from a tracking program on my phone, and trying to pull only the longitude and latitude from it. Any given line in the data looks more or less like this:

{"lon":-122.3083848,"time":1.273515839496E9,"source":"skyhook","nap":28,"altitude":0,"name":"location","hpe" :29,"bearing":0,"ncell":0,"lat":47.6544453}

I've run it through this command:

grep skyhook log-2010-05-10_18-17-28.json | cut -d"," -f1,10

to get this:

{"lon":-122.30872015,"lat":47.65812201}
{"lon":-122.3076686,"lat":47.6569975}
{"lon":-122.3079161,"lat":47.656395}
{"lon":-122.3096168,"lat":47.656218}
{"lon":-122.3096285,"lat":47.656206}

Which is a lot nicer, but I would prefer not to have to hand remove the non-number characters by hand since there are thousands of data points. what I could do to get it to just be longitude and latitude in 'number number' format?

View 8 Replies View Related

General :: Why Is Reading A FILE Faster Than Reading A VARIABLE?

May 4, 2011

I don't understand the results of a simple performance test I ran using two basic scripts (running on a high end server):

perfVar.zsh :

#!/bin/zsh -f
MYVAR=`cat $1`
for i in {1..10}

[code]...

Performance test result:

> time ./perfVar.zsh BigTextFile > /dev/null
./perfVar.zsh FE > /dev/null 6.86s user 0.32s system 100% cpu 7.177 total
> time ./perfCat.zsh BigTextFile > /dev/null
./perfCat.zsh FE > /dev/null 0.01s user 0.10s system 91% cpu 0.118 total

I would have thought that accessing a VARIABLE was way faster than reading a FILE on the file system... Why this result ?Is there a way to optimize the perfCat.zsh script by reducing the number of accesses to the file system ?

View 3 Replies View Related

Programming :: Bash: Split A Text File Into An Array?

Sep 18, 2010

I have a file (called twitterstatus.tmp) that looks like this:

Code:

<status>
<id>24854489768</id>
<text>Are we gonna ride the sun home?</text>
<id>55266987</id>

[code].....

How could I feed this into an array, with each element containing everything between the <status> </status> tags?

View 9 Replies View Related

General :: Searching Text Files For Large Numbers?

Dec 31, 2010

I am looking for a way to search for large numbers in text files and print the nearby lines.

For example if I had a text file like:

Event: 11
blah: 3
blah: 41 bleh: 19
Event: 2
blah: 31

[Code].....

View 1 Replies View Related

General :: Use Sender Or Any Thing In Header As Ame Of Storing Mail File In Procmailrc?

Apr 19, 2011

I want to know how can I use sender an receiver of the email in name of file for storing mail in procmailrc. I made one but it does not work.

Quote:

SUBJECT=`formail -xSubject:` # regular field
FROM=`formail -rt -xTo:` # special case
:0 b
* ^FROM.*
| sed -e '/^To: +?[0-9]*$/,/report/!d' > ${FROM}${SUBJECT}--`mktemp 20`date +%y-%m-%d-%S--`XXXXXX`

it works when I use :

Quote:

| sed -e '/^To: +?[0-9]*$/,/report/!d' > `mktemp 20`date +%y-%m-%d-%S--`XXXXXX`

View 1 Replies View Related

Programming :: Python - Get Text File Data Into An Array On Python?

Nov 30, 2009

I've already used line split stuff to transform my data into something like this in a text file:

Code:

['1', '1', '3', '20.7505207']
['2', '1', '3', '23.0488319']
['3', '1', '3', '-1.5768747']
['4', '1', '3', '-26.4772491']

[code]....

How can I get this on a python program so I can manipulate it as an array?

View 3 Replies View Related

Programming :: Reading Lines To An Array And Generate Dynamic Zenity List?

May 18, 2011

explanation what I want to do exactly:I have a textfile which looks for instance like this:

file.txt:
...
something=else to do

[code]....

View 14 Replies View Related

General :: DU Style Directory Listing With File Numbers

Sep 6, 2010

Is there a command to return a recursive listing of sub-directories and the number of files in them? I have found plenty of ways to give me the total number of files in a directory structure, but none that gives a list of the sub-directories with the number of files in them. "du" gives me a listing of directories with their sizes, but I couldn't find an option (or any other way) to give me the number of files as well. Ideally, I'd like to get list with "Size" "Files" "Dir name" - And the order of the columns doesn't matter. Is there a "simple" command line solution or do I need a shell script for that?

View 5 Replies View Related

General :: Replace Sequential Numbers In A File With A Different Sequence Using Sed?

Apr 11, 2010

I am trying to find a way to replace a set of sequential numbers in a file with a different sequence using sed. This might be done easier using awk or some sort of bash script, but it seems to me there must be a way to do this easily with sed. Basically, what I am editing is a Cisco switch config. I want to change the sequence of ports to a different numbered sequence. Here is an example of what I am trying to do.I want to change for example, the file:

Code:
cat testfile
interface FastEthernet0/1

[code]...

View 6 Replies View Related

General :: Replace Text In One File With Text From Another File Using Sed?

Apr 28, 2010

How could I replace text in one file with text from another file using sed?

The text in each of the files would be surrounded by a starting and ending delimiter or a starting tag, say like /* */ so to easily find them.

View 8 Replies View Related

General :: Reading Contents Of PDF File?

Jun 8, 2011

is there any API to read content of PDF file & store it in buffer?

View 14 Replies View Related

General :: Reading Info From One File In To Another?

Nov 17, 2010

been playing around making a server to play some games on running centos 5.5

what ive spent a while looking for (a few days) is a way to make a file which i will call startup this will contain some values

Code:
mod_directory="etpub"
port="27960"
log_name="console.log"
vm="0"
dedicated="2"

[Code].....

View 1 Replies View Related

Programming :: Reading And Writing Text Files In C?

Jan 1, 2011

Reading and writing text files in C?

View 9 Replies View Related

General :: Reading The Contents Of A .bkf File Using A Non-Microsoft OS?

Apr 20, 2010

I have a .bkf backup file, created by the Backup utility that Microsoft provides with Windows XP. Is there a way to read the contents of the file using a non-Microsoft OS, preferably Mac OS X or Linux?

View 1 Replies View Related

General :: Oracle - Reading Alert Log File?

Mar 2, 2011

My requirement is that I wanted a shell script which should read the alert.log(oracle) and should send the alert to my email if any error encountered on daily basis. I have a script which does the same job but at the same time it creates a new alert.log whenever any error occur. But I don't want the new alert log I wanted to read the same alert log daily and if any new error come should alert as email.

View 3 Replies View Related

General :: Reading File Into Variable In Bash?

Mar 21, 2011

I know that cat can output the file, but how do you store that output in a variable to process:

Code:

CONTENT=cat file.txt

This doesn't seem to work?

View 3 Replies View Related

General :: Reading A File From A Remote Server?

Oct 15, 2010

I have an situation where I want to read a file into my script that lie on a remote server. I have ssh-keys set up just don't know how to do this.

View 7 Replies View Related







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