Sponsored Content
Full Discussion: Reading a file into an array
Top Forums UNIX for Dummies Questions & Answers Reading a file into an array Post 302336396 by zaxxon on Wednesday 22nd of July 2009 04:17:09 AM
Old 07-22-2009
Executing your script without shebang will use a default shell I guess or the one that you current use. With the shebang you tell the system explicit which shell to use to execute that script. Since I wrote the array how it is written in ksh, it would be good to tell the system to explicit use ksh by the shebang.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: Reading out rows of a file into a dynamic array and check first literal

Hello, i have a file "Movie.ini" looking e.g. like follows * MOVIE A bla bla MOVIE B blubb blubb MOVIE C I'd like to read the file "Movie.ini" with cat and grep and check whether it includes the string MOVIE only with a '*' at the beginnig. By doing "cat Movie.ini| grep MOVIE... (14 Replies)
Discussion started by: ABE2202
14 Replies

2. Shell Programming and Scripting

Reading from array

Hi, I have an array like below... Table="table1" Table="table2" Table="table3" Table="table4" ..... Table="tablen" I want to retireve the values from the array and need to pass this to a db2 command to create a view like below. the number of values in the array will vary ... (1 Reply)
Discussion started by: ratheeshjulk
1 Replies

3. Programming

Reading Scientific notation from file and storing in array

Hi, I am trying to read a set of numbers that are in scientific notation into a file so I can do some math on them, but when I display the array contents the numbers aren't the same as the numbers in the file. Could someone explain why? Thanks. int main() { double fArray; ... (3 Replies)
Discussion started by: Filter500
3 Replies

4. Shell Programming and Scripting

Reading from a file and assigning to an array in perl

I wrote a simply perl that searched a file for a particualr value and if it found it, rite it and the next three lines to a file. Now I have been asked to check those next three lines for a different value and only write those lines if it finds the second value. I was thinking the best way to... (1 Reply)
Discussion started by: billprice13
1 Replies

5. Shell Programming and Scripting

reading data from a file to an array

I need some help with this code below, i doesnt know why it will run twice with my function, but my function only got if else, any other way that can read line and put into array? while read line; do read -A array <<<$line n=${#array} for ((i=1;i<$n;i++)); do print... (1 Reply)
Discussion started by: gavin_L
1 Replies

6. Shell Programming and Scripting

Help with reading column in array

I have some version problem to use this code in my server while read line; do read -A array <<<$line <---------- the server dont read <<< n=${#array} for ((i=1;i<$n;i++)); do print "${array}" done func=${array} data1=${array} data2=${array} ... (1 Reply)
Discussion started by: gavin_L
1 Replies

7. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

8. Shell Programming and Scripting

Reading a file into array

Hi, I need to read a file into array and print them in a loop:- 1st file :-cat a.txt RC1 RC2 RC3 RC4 My Program:- #!/bin/ksh index=0 while do read cnt<a.txt print "cnt value is ${cnt} index=`expr $index + 1` done Code tags for code, please. (5 Replies)
Discussion started by: satishmallidi
5 Replies

9. Shell Programming and Scripting

Reading a file into an array

Hi I have a file with contents as below : server | ABC Issue : File System Missing XYZ Issue : Wrong Syntax PQR Issue : Old File to be removed Now I am looking for an o/p similar to server <tab> ABC Issue : File System Missing <tab> XYZ Issue : Wrong Syntax <tab>... (4 Replies)
Discussion started by: deo_kaustubh
4 Replies

10. Shell Programming and Scripting

Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies
WORDEXP(3)						     Linux Programmer's Manual							WORDEXP(3)

NAME
wordexp, wordfree - perform word expansion like a posix-shell SYNOPSIS
#include <wordexp.h> int wordexp(const char *s, wordexp_t *p, int flags); void wordfree(wordexp_t *p); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): wordexp(), wordfree(): _XOPEN_SOURCE DESCRIPTION
The function wordexp() performs a shell-like expansion of the string s and returns the result in the structure pointed to by p. The data type wordexp_t is a structure that at least has the fields we_wordc, we_wordv, and we_offs. The field we_wordc is a size_t that gives the number of words in the expansion of s. The field we_wordv is a char ** that points to the array of words found. The field we_offs of type size_t is sometimes (depending on flags, see below) used to indicate the number of initial elements in the we_wordv array that should be filled with NULLs. The function wordfree() frees the allocated memory again. More precisely, it does not free its argument, but it frees the array we_wordv and the strings that points to. The string argument Since the expansion is the same as the expansion by the shell (see sh(1)) of the parameters to a command, the string s must not contain characters that would be illegal in shell command parameters. In particular, there must not be any unescaped newline or |, &, ;, <, >, (, ), {, } characters outside a command substitution or parameter substitution context. If the argument s contains a word that starts with an unquoted comment character #, then it is unspecified whether that word and all fol- lowing words are ignored, or the # is treated as a non-comment character. The expansion The expansion done consists of the following stages: tilde expansion (replacing ~user by user's home directory), variable substitution (replacing $FOO by the value of the environment variable FOO), command substitution (replacing $(command) or `command` by the output of command), arithmetic expansion, field splitting, wildcard expansion, quote removal. The result of expansion of special parameters ($@, $*, $#, $?, $-, $$, $!, $0) is unspecified. Field splitting is done using the environment variable $IFS. If it is not set, the field separators are space, tab and newline. The output array The array we_wordv contains the words found, followed by a NULL. The flags argument The flag argument is a bitwise inclusive OR of the following values: WRDE_APPEND Append the words found to the array resulting from a previous call. WRDE_DOOFFS Insert we_offs initial NULLs in the array we_wordv. (These are not counted in the returned we_wordc.) WRDE_NOCMD Don't do command substitution. WRDE_REUSE The argument p resulted from a previous call to wordexp(), and wordfree() was not called. Reuse the allocated storage. WRDE_SHOWERR Normally during command substitution stderr is redirected to /dev/null. This flag specifies that stderr is not to be redirected. WRDE_UNDEF Consider it an error if an undefined shell variable is expanded. RETURN VALUE
In case of success 0 is returned. In case of error one of the following five values is returned. WRDE_BADCHAR Illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }. WRDE_BADVAL An undefined shell variable was referenced, and the WRDE_UNDEF flag told us to consider this an error. WRDE_CMDSUB Command substitution occurred, and the WRDE_NOCMD flag told us to consider this an error. WRDE_NOSPACE Out of memory. WRDE_SYNTAX Shell syntax error, such as unbalanced parentheses or unmatched quotes. VERSIONS
wordexp() and wordfree() are provided in glibc since version 2.1. CONFORMING TO
POSIX.1-2001. EXAMPLE
The output of the following example program is approximately that of "ls [a-c]*.c". #include <stdio.h> #include <stdlib.h> #include <wordexp.h> int main(int argc, char **argv) { wordexp_t p; char **w; int i; wordexp("[a-c]*.c", &p, 0); w = p.we_wordv; for (i = 0; i < p.we_wordc; i++) printf("%s ", w[i]); wordfree(&p); exit(EXIT_SUCCESS); } SEE ALSO
fnmatch(3), glob(3) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2008-07-14 WORDEXP(3)
All times are GMT -4. The time now is 02:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy