The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating an array to hold posix thread ids: Only dynamic array works kmehta High Level Programming 4 09-21-2008 09:24 PM
concatinating data kingofprussia UNIX for Dummies Questions & Answers 1 05-06-2008 11:16 PM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 09:42 AM
Concatinating line by line from one file to other me_haroon AIX 1 06-30-2006 03:48 AM
copying or concatinating string from 1st bit, leaving 0th bit jazz High Level Programming 2 11-10-2005 12:38 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2009
mail2sant mail2sant is offline
Registered User
  
 

Join Date: Apr 2008
Location: bangalore
Posts: 71
concatinating the array

i need to concatenate array like.
eg:

a = { a,b,c}
b= { 1,2,3}

result should be like below

c={a1,b2,c3}

can u help me out
  #2 (permalink)  
Old 05-07-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 553

Code:
$
$ perl -e '{
>   @a = qw/a b c/; print "Array a =\n",join("\n",@a),"\n";
>   @b = qw/1 2 3/; print "Array b =\n",join("\n",@b),"\n";
>   foreach $i (0..$#a){ $c[$i] = $a[$i].$b[$i]; } print "Array c = \n",join("\n",@c),"\n";}'
Array a =
a
b
c
Array b =
1
2
3
Array c =
a1
b2
c3
$

tyler_durden

________________________________________________
"Without pain, without sacrifice, we would have nothing."
  #3 (permalink)  
Old 05-07-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,099

Code:
i=0
a=(a b c)
b=(1 2 3)
sum=$((${#a[@]}-1))
while [ $i -le $sum ];do
echo ${a[$i]}${b[$i]}
i=$(($i+1))
done

perl:

Code:
my @arr1=(a,b,c);
my @arr2=(1,2,3);
my @arr3=map {$arr1[$_].$arr2[$_]} 0..$#arr1;
print join "|", @arr3;


Last edited by summer_cherry; 05-07-2009 at 06:31 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0