how to convert array into the string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to convert array into the string
# 1  
Old 06-25-2009
how to convert array into the string

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 spaces between the letters. I am not sure why.... Is there a way to print this array so no blanks will be added btw the latters, another words how to convert this array to the original format (no blank between letters)


Thanks a lot for any advice....
# 2  
Old 06-25-2009
doing 'man ksh' yields the following:
Code:
     The shell supports a one-dimensional array facility. An ele-
     ment  of  an  array variable is referenced by a subscript. A
     subscript is denoted by  a  [,  followed  by  an  arithmetic
     expression  (see Arithmetic Evaluation  below) followed by a
     ]. To assign values to an array, use set -A name value  ....
     The  value  of  all  subscripts  must  be  in the range of 0
     through 4095. Arrays need not be declared. Any reference  to
     a variable with a valid subscript is legal and an array will
     be created if necessary. Referencing an array without a sub-
     script  is  equivalent  to  referencing the element 0. If an
     array identifier with subscript * or @  is  used,  then  the
     value  for each of the elements is substituted (separated by
     a field separator character).

Tried resetting IFS to nothing?
# 3  
Old 06-25-2009
If you just want to remove the spaces, send it the 'tr', and have it delete them.

echo "s t r i n g "| tr -d ' '

bd - I hope this helps.
# 4  
Old 06-25-2009
use awk
Code:
awk 'BEGIN{
    A=" 3498 NORDEA - INDX LINKED NORY"
    m=split(A,a,"")
    for(i=1;i<=m;i++){
        print a[i]
    }
}

or
Code:
# echo  "3498 NORDEA - INDX LINKED NORY" | awk 'BEGIN{FS=""}{for(i=1;i<=m;i++)print $i}'

# 5  
Old 06-25-2009

Code:
string=$( printf "%s" "${ARR[@]}" )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert String to an Array using shell scripting in JSON file.

This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "10.38.32.202" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies

2. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

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

3. Shell Programming and Scripting

Convert values in an array using a loop

I have a headerless array of 1000 columns x 100000 rows. The array only contains 4 values; 0/0, 0/1, 1/1, ./. Here I am showing the 1st 3 rows and columns of the input array 0/0 0/0 1/1 0/1 0/1 0/1 0/0 ./. 0/0 0/0 0/0 0/0 I would like to convert the values in... (9 Replies)
Discussion started by: Geneanalyst
9 Replies

4. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

5. Homework & Coursework Questions

passing letters from an array into a string for string comparison

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

PERL : Read an array and write to another array with intial string pattern checks

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

7. Shell Programming and Scripting

Help with convert string

Hi. I will be very appreciated for help. I need replace all characters into string with \ (backslash) I mean if I have word abcdefg as input. How I can convert it to \a\b\c\d\e\f\g Thanks and best regards. Staas. (5 Replies)
Discussion started by: beckss
5 Replies

8. Shell Programming and Scripting

Convert array data to excel format

I need your help in changing the script I have data has below text file :> cat my_emp Employee array(0) Name : Albert No : 1234 Address: stationstraat City: Utrecht Employee array (1) Name : Kouwen No : 1256 Address: stationstraat City: Amsterdam Employee array (2) Name : Peter... (2 Replies)
Discussion started by: LinuxLearner
2 Replies

9. Shell Programming and Scripting

convert variable content to array

Hi All, I have a variable in a shell script which holds let say n paarmeteres with space separate them : $var = par1 par2 par3 par4 parn; so if I print this variable this is what I'll see: par1 par2 par3 par4 parn I need to insert each parameter to an array , so I can go over on each... (3 Replies)
Discussion started by: Alalush
3 Replies

10. Programming

Point and Array Convert Problem

In this statement,"A" of type "int",being converted to "pointer toarray of int".(cvtdiftypes) Please help me! #include <stdio.h> #include <stdlib.h> int m,k; const int max =20; int A; //**************************************************** // Input Matrix ... (0 Replies)
Discussion started by: zhshqzyc
0 Replies
Login or Register to Ask a Question