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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2007
Registered User
 

Join Date: Sep 2007
Posts: 148
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..
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-03-2007
Registered User
 

Join Date: Oct 2007
Posts: 153
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.
Reply With Quote
  #3 (permalink)  
Old 12-03-2007
Registered User
 

Join Date: Sep 2007
Posts: 148
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..
Reply With Quote
  #4 (permalink)  
Old 12-04-2007
Registered User
 

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

Join Date: Sep 2007
Posts: 148
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 ..
Reply With Quote
  #6 (permalink)  
Old 12-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 148
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]
		 }
Reply With Quote
  #7 (permalink)  
Old 12-04-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,423
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.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0