Sponsored Content
Top Forums Shell Programming and Scripting Pipe text from a file into an array Post 302282942 by grahambo2005 on Monday 2nd of February 2009 07:58:51 AM
Old 02-02-2009
Pipe text from a file into an array

Hi Guys I have a question about filling up an array

I have a file called USER_FILE.txt
it contains the following:

Real Name:Thomas A Username:THOMAS_A
Real Name:Thomas B Username:THOMAS_B
Real Name:Thomas C Username:THOMAS_C
Real Name:Thomas D Username:THOMAS_D
Real Name:Thomas E Username:THOMAS_E

I want to put this data into an array
here is what I am doing:

set -a User_array [ < USER_FILE.txt ]

however I do not believe this is working as when I run

echo ${User_array[0]}

nothing appears

Basically I need
echo ${User_array[0]}
to contain:
Real Name:Thomas A Username:THOMAS_A

echo ${User_array[1]}
to contain:
Real Name:Thomas B Username:THOMAS_B

echo ${User_array[2]}
to contain:
Real Name:Thomas C Username:THOMAS_C

etc etc

what am I doing wrong?

Thanks G
 

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Wall, Write, select users, pipe a text file, HELP Before I'm Bald!

OK... I'm fairly new to unix having the admin handed to me on a platter w/almost no training. However, being a programmer, I do pick up things fairly easily, but this one is getting the best of me. I have a unix server that runs multiple versions of the same ERP system, hand crafted for our... (1 Reply)
Discussion started by: chimodel
1 Replies

2. Shell Programming and Scripting

input text from file into 2d array

Hi all I have a little brainscratcher here. I want to draw a pie chart from data in a text file. The drawing of the graph works fine, if I insert the data manually into a 2d array. Now I want to pull the data from a text file (which was created using a uniq -c command) see sample below.... (2 Replies)
Discussion started by: pietie
2 Replies

3. UNIX for Dummies Questions & Answers

Problem working with Pipe Delimited Text file

Hello all: I have a following textfile data with name inst1.txt HDR|ABCD|10-13-2008 to 10-19-2008.txt|10-19-2008|XYZ DTL|H|5464-1|0|02-02-2008|02-03-2008||||F||||||||| DTL|D|5464-1|1|02-02-2008|02-03-2008|1||JJJ DTL|D|5464-1|2|02-02-2008|02-03-2008|1||JJJ... (9 Replies)
Discussion started by: ravi0435
9 Replies

4. UNIX for Dummies Questions & Answers

Replacing a field in pipe delimited TEXT File

Hi, I want to replace a field in a text delimited file with the actual number of records in the same file. HDR|ABCD|10-13-2008 to 10-19-2008.txt|10-19-2008|XYZ DTL|0|5464-1|0|02-02-2008|02-03-2008||||F||||||||| DTL|1|5464-1|1|02-02-2008|02-03-2008|1||JJJ... (3 Replies)
Discussion started by: ravi0435
3 Replies

5. Shell Programming and Scripting

pipe command for array

Hi Folks, very basic question, how to do command piping for an array? suppose i have names as an array, when I write this script: #!/usr/bin/sh date=`date +%y%m%d`; names="a b" for name in ${names} do extract -tz +8 person 'income$|expense$' /home/ricki/$name/$date*.xml | tab -d -cols... (1 Reply)
Discussion started by: rickirick
1 Replies

6. Shell Programming and Scripting

Bash Script Help...search then read from file: change text and pipe back...

Hello, I am trying to make a bash script that can pull data from a file and then change one part of said data. I want to search by username and pull the full line. That way there is a way to replace just one part of that line then return it back to the file. My Data is stored like: ... (1 Reply)
Discussion started by: serverfull
1 Replies

7. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

8. Shell Programming and Scripting

How to use pipe operator as simple character in text file?

Hello all, I have two files which are cmd and disk. `$cat cmd lsdev | grep -iw` `$cat disk hdisk2` Now I want to use the contents of both the files in a way such that `lsdev | grep -iw` command works for hdisk2 when I write the following script: `!#/bin/sh cmd1="$( sed -n... (4 Replies)
Discussion started by: ravi.trivedi
4 Replies

9. Shell Programming and Scripting

Array & text file

Hi all, i have a text file such as: 10 17:54:47,213 10 17:54:47,214 10 17:54:49,338 10 17:54:49,399 10 17:54:50,402 10 17:54:50,403 11 17:54:47,213 11 17:54:47,213 11 17:54:49,362 11 17:54:49,422 11 17:54:50,429 11 17:54:50,429 11 17:54:50,429 11 17:54:50,429 11 17:54:51,510 12... (10 Replies)
Discussion started by: sbamap
10 Replies

10. Linux

How to run commands with pipe from text file?

Hello, I have standard loop while read -r info; do command $info done < info in info text file I have multiple commands each on line that I want to execute. When I used them in console they worked, but not with this loop. This is one of the commands in info file: grep... (4 Replies)
Discussion started by: adamlevine
4 Replies
pgmres(4rheolef)						    rheolef-6.1 						  pgmres(4rheolef)

NAME
pgmres -- generalized minimum residual method SYNOPSIS
template <class Matrix, class Vector, class Preconditioner, class SmallMatrix, class SmallVector, class Real, class Size> int pgmres (const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, SmallMatrix &H, const SmallVector& dummy, Size m, Size &max_iter, Real &tol); EXAMPLE
The simplest call to pgmres has the folling form: double tol = 1e-7; size_t max_iter = 100; size_t m = 6; boost::numeric::ublas::matrix<double> H(m+1,m+1); vec<double,sequential> dummy; int status = pgmres (a, x, b, ic0(a), H, dummy, m, max_iter, tol); DESCRIPTION
pgmres solves the unsymmetric linear system Ax = b using the generalized minimum residual method. The return value indicates convergence within max_iter (input) iterations(0), or no convergence within max_iter iterations(1). Upon suc- cessful return, output arguments have the following values: x approximate solution to Ax = b max_iter the number of iterations performed before the tolerance was reached tol the residual after the final iteration In addition, M specifies a preconditioner, H specifies a matrix to hold the coefficients of the upper Hessenberg matrix constructed by the pgmres iterations, m specifies the number of iterations for each restart. pgmres requires two matrices as input, A and H. The matrix A, which will typically be a sparse matrix) corresponds to the matrix in the linear system Ax=b. The matrix H, which will be typically a dense matrix, corresponds to the upper Hessenberg matrix H that is constructed during the pgmres iterations. Within pgmres, H is used in a different way than A, so its class must supply different functionality. That is, A is only accessed though its matrix-vector and transpose-matrix-vector multiplication functions. On the other hand, pgmres solves a dense upper triangular linear system of equations on H. Therefore, the class to which H belongs must provide H(i,j) operator for element acess. NOTE
It is important to remember that we use the convention that indices are 0-based. That is H(0,0) is the first component of the matrix H. Also, the type of the matrix must be compatible with the type of single vector entry. That is, operations such as H(i,j)*x(j) must be able to be carried out. pgmres is an iterative template routine. pgmres follows the algorithm described on p. 20 in @quotation Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods, 2nd Edition, R. Barrett, M. Berry, T. F. Chan, J. Demmel, J. Donato, J. Dongarra, V. Eijkhout, R. Pozo, C. Romine, H. Van der Vorst, SIAM, 1994, ftp.netlib.org/templates/templates.ps. @end quotation The present implementation is inspired from IML++ 1.2 iterative method library, http://math.nist.gov/iml++. IMPLEMENTATION
template <class SmallMatrix, class Vector, class SmallVector, class Size> void Update(Vector &x, Size k, SmallMatrix &h, SmallVector &s, Vector v[]) { SmallVector y = s; // Back solve: for (int i = k; i >= 0; i--) { y(i) /= h(i,i); for (int j = i - 1; j >= 0; j--) y(j) -= h(j,i) * y(i); } for (Size j = 0; j <= k; j++) { x += v[j] * y(j); } } template<class Real> void GeneratePlaneRotation(Real &dx, Real &dy, Real &cs, Real &sn) { if (dy == Real(0)) { cs = 1.0; sn = 0.0; } else if (abs(dy) > abs(dx)) { Real temp = dx / dy; sn = 1.0 / ::sqrt( 1.0 + temp*temp ); cs = temp * sn; } else { Real temp = dy / dx; cs = 1.0 / ::sqrt( 1.0 + temp*temp ); sn = temp * cs; } } template<class Real> void ApplyPlaneRotation(Real &dx, Real &dy, Real &cs, Real &sn) { Real temp = cs * dx + sn * dy; dy = -sn * dx + cs * dy; dx = temp; } template <class Matrix, class Vector, class Preconditioner, class SmallMatrix, class SmallVector, class Real, class Size> int pgmres (const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, SmallMatrix &H, const SmallVector&, const Size &m, Size &max_iter, Real &tol) { odiststream* p_derr = &derr; std::string label = "pgmres"; if (p_derr) (*p_derr) << "[" << label << "] #iteration residue" << std::endl; Vector w; SmallVector s(m+1), cs(m+1), sn(m+1); Size i; Size j = 1; Size k; Real resid; Real normb = norm(M.solve(b)); Vector r = M.solve(b - A * x); Real beta = norm(r); if (normb == Real(0)) { normb = 1; } resid = norm(r) / normb; if (resid <= tol) { tol = resid; max_iter = 0; return 0; } Vector *v = new Vector[m+1]; while (j <= max_iter) { v[0] = r * (1.0 / beta); // ??? r / beta s = 0.0; s(0) = beta; for (i = 0; i < m && j <= max_iter; i++, j++) { w = M.solve(A * v[i]); for (k = 0; k <= i; k++) { H(k, i) = dot(w, v[k]); w -= H(k, i) * v[k]; } H(i+1, i) = norm(w); v[i+1] = w * (1.0 / H(i+1, i)); // ??? w / H(i+1, i) for (k = 0; k < i; k++) { ApplyPlaneRotation(H(k,i), H(k+1,i), cs(k), sn(k)); } GeneratePlaneRotation(H(i,i), H(i+1,i), cs(i), sn(i)); ApplyPlaneRotation(H(i,i), H(i+1,i), cs(i), sn(i)); ApplyPlaneRotation(s(i), s(i+1), cs(i), sn(i)); resid = abs(s(i+1)) / normb; if (p_derr) (*p_derr) << "[" << label << "] " << j << " " << resid << std::endl; if (resid < tol) { Update(x, i, H, s, v); tol = resid; max_iter = j; delete [] v; return 0; } } Update(x, m - 1, H, s, v); r = M.solve(b - A * x); beta = norm(r); resid = beta / normb; if (p_derr) (*p_derr) << "[" << label << "] " << j << " " << resid << std::endl; if (resid < tol) { tol = resid; max_iter = j; delete [] v; return 0; } } tol = resid; delete [] v; return 1; } rheolef-6.1 rheolef-6.1 pgmres(4rheolef)
All times are GMT -4. The time now is 06:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy