Sponsored Content
Top Forums Shell Programming and Scripting Get tokens from line and put them into an array Post 302703961 by msabhi on Thursday 20th of September 2012 04:25:52 PM
Old 09-20-2012
Code:
echo "IDNO H1 H2 H3 HT Q1 Q2 Q3 Q4 Q5 M1 M2 EXAM" | while read -a array
do
echo "${array[0]}"
done

This User Gave Thanks to msabhi For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing tokens from cmd line

Hi everyone. I am trying to develop my own shell,and i am in the part of redirection. let's say the user gives as input cat test > test2 in the array of arguments i want to keep only arg=cat,arg=test. ">" token is not an input file so cat cannot worka and test2 is output.how can i remove > and... (1 Reply)
Discussion started by: bashuser2
1 Replies

2. Shell Programming and Scripting

Put output into an array

I'm trying to take the output of an environment that has multiple strings ex. # echo $SSH_CLIENT 192.168.1.1 57039 22 I need that IP... so I can set it to another environment. Thank you (3 Replies)
Discussion started by: adelsin
3 Replies

3. Shell Programming and Scripting

Put lines of a file in an array with awk

Hello, Is there any way in awk to put every line of a file in an array and so we can like this print the line we want. For example, if we have this file aaa eee bbb fff ccc ggg ddd hhh So we can print to the output the 3rd line only ccc ggg If it is possible, please put the... (7 Replies)
Discussion started by: rany1
7 Replies

4. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

5. Programming

how to put element of an array to first position.

hi, I have a array like my $array = ( "apple","ball","cat","dog","elephant"); how to push some element in the array to the first position. for example my final array should be elephant apple ball cat dog (5 Replies)
Discussion started by: vprasads
5 Replies

6. Programming

put an 2D array in shared memory

Hi, I want to make 2 simple programs communicate each other with shared memory. The programs will share an 2D array. In the first program (intarr.c) i create an x array which is: 1 2 3 4 5 6 7 8 9 10 11 12 and i call the second program (intarr2.c) with execvp(); giving it the segment id as an... (2 Replies)
Discussion started by: giampoul
2 Replies

7. Shell Programming and Scripting

Extract specific text from variable and put it into array

Dear community, I have to do something too hard for me :rolleyes:. I hope you can help me. This is an output coming from Oracle query, stored in a file called query.out, there are many rows, but I read them, one by one, using while/read/done. Assuming each row is contained into $line variable... (8 Replies)
Discussion started by: Lord Spectre
8 Replies

8. Shell Programming and Scripting

How do I put data piped to my script into an array for repeated processing

Hi folks, Sorry for something I'm sure was answered already, I just could not find it in a search of the forums. I am trying to build a script that eats a config file as: cat file.cnf | ConProcess.shWhat I want to do inside the script is: !#/usr/bin/bash # captured piped cat into an... (6 Replies)
Discussion started by: Marc G
6 Replies

9. Shell Programming and Scripting

Perl : Large amount of data put into an array

This basic code works. I have a very long list, almost 10000 lines that I am building into the array. Each line has either 2 or 3 fields as shown in the code snippit. The array elements are static (for a few reasons that out of scope of this question) the list has to be "built in". It... (5 Replies)
Discussion started by: sumguy
5 Replies

10. Shell Programming and Scripting

Read file and get the data then put it in array

Hi, I have a file called "readfile" it contains below parameters #cat readfile word=/abc=225,/abc/cba=150 three=12 four=45 five=/xyz/yza likewise multiple line. From the above file, I have to read "word" output should be like, /abc /abc/cba these values need to be put in... (3 Replies)
Discussion started by: munna_dude
3 Replies
STRTOK(3)								 1								 STRTOK(3)

strtok - Tokenize string

SYNOPSIS
string strtok (string $str, string $token) DESCRIPTION
string strtok (string $token) strtok(3) splits a string ($str) into smaller strings (tokens), with each token being delimited by any character from $token. That is, if you have a string like "This is an example string" you could tokenize this string into its individual words by using the space character as the token. Note that only the first call to strtok uses the string argument. Every subsequent call to strtok only needs the token to use, as it keeps track of where it is in the current string. To start over, or to tokenize a new string you simply call strtok with the string argument again to initialize it. Note that you may put multiple tokens in the token parameter. The string will be tokenized when any one of the characters in the argument are found. PARAMETERS
o $str - The string being split up into smaller strings (tokens). o $token - The delimiter used when splitting up $str. RETURN VALUES
A string token. EXAMPLES
Example #1 strtok(3) example <?php $string = "This is an example string"; /* Use tab and newline as tokenizing characters as well */ $tok = strtok($string, " "); while ($tok !== false) { echo "Word=$tok<br />"; $tok = strtok(" "); } ?> The behavior when an empty part was found changed with PHP 4.1.0. The old behavior returned an empty string, while the new, correct, behavior simply skips the part of the string: Example #2 Old strtok(3) behavior <?php $first_token = strtok('/something', '/'); $second_token = strtok('/'); var_dump($first_token, $second_token); ?> The above example will output: string(0) "" string(9) "something" Example #3 New strtok(3) behavior <?php $first_token = strtok('/something', '/'); $second_token = strtok('/'); var_dump($first_token, $second_token); ?> The above example will output: string(9) "something" bool(false) NOTES
Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. SEE ALSO
split(3), explode(3). PHP Documentation Group STRTOK(3)
All times are GMT -4. The time now is 05:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy