The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Concatenation Asteroid Shell Programming and Scripting 11 04-04-2007 06:15 AM
File Concatenation samit_9999 UNIX for Dummies Questions & Answers 3 11-21-2006 06:26 AM
string concatenation systemsb UNIX for Dummies Questions & Answers 7 04-04-2006 12:03 PM
Implementing Concatenation(cat) toughguy2handle High Level Programming 2 09-22-2005 02:10 AM
Concatenation videsh77 Shell Programming and Scripting 2 12-14-2004 06:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-04-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
cannot get logic for concatenation awk

Hello friends,

I have a problem in printing an array..

Example if my array line contains 4 elements like following
line[1]=0002 , line[2]=202200, line[3]=200002, line[4]= 300313

Now
Code:
 one = sprintf line[1] line[2] line[3] line[4]
will concatenate my whole array to one.

But I am not sure about the array index how long will it will be ..If more big array came I need to write it again like

Code:
 one = sprintf line[1] line[2] line[3] line[4]  line[5] .....
Please help me with a logic or code .. how to loop here instead of using index explicitly..

Thanks in advance..
  #2 (permalink)  
Old 12-04-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
Code:
awk 'BEGIN{a[1]="abc";a[2]="def";print length(a)}'
2
Once you know the number of elements, you can use a for loop.
  #3 (permalink)  
Old 12-04-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by gus2000 View Post
Code:
awk 'BEGIN{a[1]="abc";a[2]="def";print length(a)}'
2
Once you know the number of elements, you can use a for loop.
Thanks for the reply ,, Yes I do know how many elements are in the array,
but my problem is to print it in one variable

suppose if my number of elements in the array is 3 ,then my commnad should look like this
Code:
input = sprint line[1] line[2] line[3]
On the other hand if the number of array element increases suppose to 4 then my command should look like
Code:
input = sprint line[1] line[2] line[3] line[4]
and like wise you can see the sprint line is varying with the index number..

That is my basic need .. pls help..
  #4 (permalink)  
Old 12-04-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
Code:
awk 'BEGIN { 
  line[1]="a"
  line[2]="b"
  line[3]="c"
  for ( i=1;i<=3;i++) {
    result=result""line[i]
  }
  print result
}'
  #5 (permalink)  
Old 12-04-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by ghostdog74 View Post
Code:
awk 'BEGIN { 
  line[1]="a"
  line[2]="b"
  line[3]="c"
  for ( i=1;i<=3;i++) {
    result=result""line[i]
  }
  print result
}'
Thank you I got that.. Many many thanks ..
  #6 (permalink)  
Old 12-04-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by ghostdog74 View Post
Code:
awk 'BEGIN { 
  line[1]="a"
  line[2]="b"
  line[3]="c"
  for ( i=1;i<=3;i++) {
    result=result""line[i]
  }
  print result
}'
Thanks I did like this

Code:
		 input = ""
		 for (i=1 ; i < j ; i ++){
		   input = sprint input "" line[i]
		 }
  #7 (permalink)  
Old 12-04-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
Quote:
Originally Posted by user_prady View Post
Thanks I did like this

Code:
		 input = ""
		 for (i=1 ; i < j ; i ++){
		   input = sprint input "" line[i]
		 }
no need : input=""
what is sprint?

input = input "" line[i] should suffice.
Sponsored Links
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 06:38 PM.


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