If your input data is processed in sequence, a text file is the perfect form. And the shell is great in handling text files. (An array is good for random access.)
A simple "echo" demo:
The read reads one line from a text file. The while will terminate the loop if the read was unsucessful i.e. at the end of the input.
Now with your application:
The braces in ${SKU_NAME} encapsulate the variable name, so ${SKU_NAME}_02 is the variable's value and the string _02 appended.
This User Gave Thanks to MadeInGermany For This Post:
Hi,
I wish to store $string1 in $string1array a character in each array element.
Then i wish to echo the entire array to the screen so that it reads as the normal string again.
I have been trying with the code below but does not work. Please help...
To put string into array:
... (5 Replies)
I am facing a strange error while creating posix threads:
Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output.
Snippet 1
This works:
--------------
int *threadids;
threadids = (int *) malloc (num_threads * sizeof(int));
... (4 Replies)
Hi All,
I'm writing a nagios check that will see if our ldap servers are in sync...
I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable
so...eg...let take the single array... (1 Reply)
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)
Hi everyone
I have one question about using array in perl. let say I have several log file in one folder.. example
test1.log
test2.log
test3.log
and the list goes on..
how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
I have an array and two variables as below,
I need to check if $datevar is present in $filename.
If so, i need to replace $filename with the values in the array.
I need the output inside an ARRAY
How can this be done.
Any help will be appreciated. Thanks in advance. (2 Replies)
ok, so here is the issue, I have 2 arrays.
I need to be able to create a loop that will find ${ARRAY1 in the text doc, and replace it with ${ARRAY2 then write the results. I already have that working. The problem is, I need it to do that same result across however many items are in the 2... (2 Replies)
Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help.
pesudo code
if == ENDSINFIVEINTS ]]; then
do... (4 Replies)
Hi experts,
I have two arrays one has the file paths to be searched in , and the other has the files to be serached.For eg
searchfile.dat will have
abc303
xyz123
i have to search for files that could be abc303*.dat or for that matter any extension . abc303*.dat.gz
The following code... (2 Replies)
hello,
i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case
i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N.
for case 1, I want to stretch N to fit M
arrayHuge
H = (... (2 Replies)
Discussion started by: f77hack
2 Replies
LEARN ABOUT OSX
read
read(n) Tcl Built-In Commands read(n)
__________________________________________________________________________________________________________________________________________________NAME
read - Read from a channel
SYNOPSIS
read ?-nonewline? channelId
read channelId numChars
_________________________________________________________________DESCRIPTION
In the first form, the read command reads all of the data from channelId up to the end of the file. If the -nonewline switch is specified
then the last character of the file is discarded if it is a newline. In the second form, the extra argument specifies how many characters
to read. Exactly that many characters will be read and returned, unless there are fewer than numChars left in the file; in this case all
the remaining characters are returned. If the channel is configured to use a multi-byte encoding, then the number of characters read may
not be the same as the number of bytes read.
ChannelId must be an identifier for an open channel such as the Tcl standard input channel (stdin), the return value from an invocation of
open or socket, or the result of a channel creation command provided by a Tcl extension. The channel must have been opened for input.
If channelId is in nonblocking mode, the command may not read as many characters as requested: once all available input has been read, the
command will return the data that is available rather than blocking for more input. If the channel is configured to use a multi-byte
encoding, then there may actually be some bytes remaining in the internal buffers that do not form a complete character. These bytes will
not be returned until a complete character is available or end-of-file is reached. The -nonewline switch is ignored if the command returns
before reaching the end of the file.
Read translates end-of-line sequences in the input into newline characters according to the -translation option for the channel. See the
fconfigure manual entry for a discussion on ways in which fconfigure will alter input.
USE WITH SERIAL PORTS
For most applications a channel connected to a serial port should be configured to be nonblocking: fconfigure channelId -blocking 0. Then
read behaves much like described above. Care must be taken when using read on blocking serial ports:
read channelId numChars
In this form read blocks until numChars have been received from the serial port.
read channelId
In this form read blocks until the reception of the end-of-file character, see fconfigure -eofchar. If there no end-of-file charac-
ter has been configured for the channel, then read will block forever.
EXAMPLE
This example code reads a file all at once, and splits it into a list, with each line in the file corresponding to an element in the list:
set fl [open /proc/meminfo]
set data [read $fl]
close $fl
set lines [split $data
]
SEE ALSO
file(n), eof(n), fblocked(n), fconfigure(n), Tcl_StandardChannels(3)KEYWORDS
blocking, channel, end of line, end of file, nonblocking, read, translation, encoding
Tcl 8.1 read(n)