11-15-2006
Its easy to loop a string with spaces. So u can substitute the , with a space and then use that new string to loop using for....
str1="value1,value2,value3"
str2=`echo $str1 | tr "," " "`
#there is a space in between the second pair of quotes
for text in $str2
do
echo "$text"
done
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi Experts,
I'm new to Shell Scripting world and need a little help from you "Scripting Gurus".
I want to convert a string (entered by a user) to array in csh. I want something like this:
echo "Enter the Numbers: "
set num = $<
Suppose, user enters:
1 2 3 4 5 6 7
This... (6 Replies)
Discussion started by: sumitgarg
6 Replies
2. Shell Programming and Scripting
Hi
I have a line/string as follows:
A=" 3498 NORDEA - INDX LINKED NORY"
which was converted into an array of characters:
p321$ echo "${ARR}"
3 4 9 8 N O R D E A - I N D X L I N K E D N O R Y
When I am trying print this array there are blank... (4 Replies)
Discussion started by: aoussenko
4 Replies
3. Programming
Hi ,
I wonder how I can set up an String array in java. I need the array so I can store different items per line so each item will be like one record. I tried something like :
String x = new String;
but when it comes to storing the data and retrieve the is when I struggle. The... (2 Replies)
Discussion started by: arizah
2 Replies
4. Shell Programming and Scripting
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)
Discussion started by: irudayaraj
2 Replies
5. Homework & Coursework Questions
attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now.
##I have an array $wordString that initializes to a string of dashes
##reflecting the number of letters in $theWord
##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies
6. Shell Programming and Scripting
Hi all,
I want to create an array variable in shell, for example:
#!/bin/sh
name="foo"
name="bar"
name="baz"
But above code didn't work, I also tried with:
name=(foo bar baz)
and
set -A name foo bar baz
but none of these worked.
Another question is how to know the shell... (6 Replies)
Discussion started by: Roy987
6 Replies
7. Shell Programming and Scripting
Hi,
I'm the beginner in bash scripting and I just want to create loop, which will create a few tables with string in name, and each time i try to do this in the following way, I receive: a=1;
while
do
echo "Plik a=$a"
for m in {1..4}
do echo "Plik m=$m"
... (7 Replies)
Discussion started by: masterqu
7 Replies
8. UNIX for Beginners Questions & Answers
value=malayalam
# i need to store the value in an array by splitting the character
#the output i need is
m
a
l
a
y
a
l
a
m
Please use CODE tags for output data as well as required by forum rules! (5 Replies)
Discussion started by: Meeran Rizvi
5 Replies
9. UNIX for Beginners Questions & Answers
I will start with an example of what I'm trying to do and then describe how I am approaching the issue.
File
PS028,005
Lexeme HRS # M #
PhraseType 1(1:1) 7(7)
PhraseLab 501 503
ClauseType ZYq0
PS028,005
Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies
10. UNIX for Beginners Questions & Answers
Test1.txt
Tom is hot
Test.sh
filename="/directory/Test1.txt"
set - A store
while IFS= read value
do
awk '{split($value,store," ")}'
done < "$filename"
echo ${#sore}
From the code in the executing file, I would like each... (8 Replies)
Discussion started by: TestKing
8 Replies
LEARN ABOUT NETBSD
prop_string_append
PROP_STRING(3) BSD Library Functions Manual PROP_STRING(3)
NAME
prop_string, prop_string_create, prop_string_create_cstring, prop_string_create_cstring_nocopy, prop_string_copy, prop_string_copy_mutable,
prop_string_size, prop_string_mutable, prop_string_cstring, prop_string_cstring_nocopy, prop_string_append, prop_string_append_cstring,
prop_string_equals, prop_string_equals_cstring -- string value property object
LIBRARY
Property Container Object Library (libprop, -lprop)
SYNOPSIS
#include <prop/proplib.h>
prop_string_t
prop_string_create(void);
prop_string_t
prop_string_create_cstring(const char *cstring);
prop_string_t
prop_string_create_cstring_nocopy(const char *cstring);
prop_string_t
prop_string_copy(prop_string_t string);
prop_string_t
prop_string_copy_mutable(prop_string_t string);
size_t
prop_string_size(prop_string_t string);
bool
prop_string_mutable(prop_string_t string);
char *
prop_string_cstring(prop_string_t string);
const char *
prop_string_cstring_nocopy(prop_string_t string);
bool
prop_string_append(prop_string_t str1, prop_string_t str2);
bool
prop_string_append_cstring(prop_string_t string, const char *cstring);
bool
prop_string_equals(prop_string_t str1, prop_string_t str2);
bool
prop_string_equals_cstring(prop_string_t string, const char *cstring);
DESCRIPTION
The prop_string family of functions operate on a string value property object type.
prop_string_create(void)
Create an empty mutable string. Returns NULL on failure.
prop_string_create_cstring(const char *cstring)
Create a mutable string that contains a copy of cstring. Returns NULL on failure.
prop_string_create_cstring_nocopy(const char *cstring)
Create an immutable string that contains a reference to cstring. Returns NULL on failure.
prop_string_copy(prop_string_t string)
Copy a string. If the string being copied is an immutable external C string reference, then the copy is also immutable and references
the same external C string. Returns NULL on failure.
prop_string_copy_mutable(prop_string_t string)
Copy a string, always creating a mutable copy. Returns NULL on failure.
prop_string_size(prop_string_t string)
Returns the size of the string, not including the terminating NUL. If the supplied object isn't a string, zero is returned.
prop_string_mutable(prop_string_t string)
Returns true if the string is mutable. If the supplied object isn't a string, false is returned.
prop_string_cstring(prop_string_t string)
Returns a copy of the string's contents as a C string. The caller is responsible for freeing the returned buffer.
In user space, the buffer is allocated using malloc(3). In the kernel, the buffer is allocated using malloc(9) using the malloc type
M_TEMP.
Returns NULL on failure.
prop_string_cstring_nocopy(prop_string_t string)
Returns an immutable reference to the contents of the string as a C string. If the supplied object isn't a string, NULL is returned.
prop_string_append(prop_string_t str1, prop_string_t str2)
Append the contents of str2 to str1, which must be mutable. Returns true upon success and false otherwise.
prop_string_append_cstring(prop_string_t string, const char *cstring)
Append the C string cstring to string, which must be mutable. Returns true upon success and false otherwise.
prop_string_equals(prop_string_t str1, prop_string_t str2)
Returns true if the two string objects are equivalent.
prop_string_equals_cstring(prop_string_t string, const char *cstring)
Returns true if the string's value is equivalent to cstring.
SEE ALSO
prop_array(3), prop_bool(3), prop_data(3), prop_dictionary(3), prop_number(3), prop_object(3), proplib(3)
HISTORY
The proplib property container object library first appeared in NetBSD 4.0.
BSD
January 21, 2008 BSD