cannot get logic for concatenation awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cannot get logic for concatenation awk
# 1  
Old 12-04-2007
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  
Old 12-04-2007
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  
Old 12-04-2007
Quote:
Originally Posted by gus2000
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  
Old 12-04-2007
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  
Old 12-04-2007
Quote:
Originally Posted by ghostdog74
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  
Old 12-04-2007
Quote:
Originally Posted by ghostdog74
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  
Old 12-04-2007
Quote:
Originally Posted by user_prady
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk concatenation issue - SQL generation

Greetings Experts, I have an excel file and I am unable to read it directly into awk (contains , " etc); So, I cleansed and copied the data into notepad. I need to generate a script that generates the SQL. Requirement: 1. Filter and select only the data that has the "mapping" as "direct"... (4 Replies)
Discussion started by: chill3chee
4 Replies

2. Shell Programming and Scripting

awk logic

I am trying to check my logic on a long awk i'm using. I have about 30 checks that I built into an awk and I "believe" I did this right, but I could be wrong. awk -F\| ' $9 !~ /\/*{1,}*/ $9 ~ /\(-{4}, {2,3}/ $9 ~ /\({6}, {2,3}\)/ $9 ~ /\(\+{5}, {2,3}\)/ $9 ~ /\(\+\+{4}, {2,3}\)/ $9 ~... (8 Replies)
Discussion started by: dagamier
8 Replies

3. Shell Programming and Scripting

Concatenation in awk not working

Hello I want to achieve the following. However the concatenation is not working mv `ls -ltr *myfile*.log|awk '{print $9}'` `ls -ltr *myfile*.log|awk '{print `date +'%d%m%y%k%M%S'` $9}'` I tried awk '{x=`date +'%d%m%y%k%M%S'` print $x "" $9}' awk '{x=`date +'%d%m%y%k%M%S'`... (2 Replies)
Discussion started by: Chetanz
2 Replies

4. Shell Programming and Scripting

How to use this logic with awk?

Hi friends, I am having 2 files, I just want to compare 2 files each containing 2 columns 1st column is lat, and 2nd column is long, if anyone can understand below logic please help me in writing script with awk.. here each field of file2 needs to be compared with std_file main counter=0... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

5. UNIX for Dummies Questions & Answers

awk for concatenation of column values

Hello, I have a table as shown below. I want to concatenate values in col2 and col3 based on a value in col4. 1 X Y A 3 Y Z B 4 A W B 5 T W A If col4 is A, then I want to concatenate col3 with itself. Otherwise it should concateneate col2 with col3. 1 X Y YY 3 Y Z YZ... (10 Replies)
Discussion started by: Gussifinknottle
10 Replies

6. Shell Programming and Scripting

Awk concatenation in different lines

Hi All I have the data as id-number 01 name-id x0 input-id x0 output-id x0 name-id x0 input-id x0 output-id x0 name-id x0 input-id x0 output-id x0 id-number 02 name-id x0 input-id x0 output-id x0 name-id x0 input-id x0 output-id x0 name-id x0 input-id x0 output-id x0 . . I... (4 Replies)
Discussion started by: posner
4 Replies

7. UNIX for Dummies Questions & Answers

Need help in logic using awk command

I have task to find out the min,max, average value of each service for example i searched for " StatementService " $awk '/VST.*StatementService:/{print $3,$4,$19,$22,$25}' performance.log > smp.log $cat smp.log amexgtv VST: : StatementService:1860 StatementService:getCardReference:0... (3 Replies)
Discussion started by: senthil.ak
3 Replies

8. Shell Programming and Scripting

need an awk script/logic

In one data file i have values like this a b c 1 2 e f g 2 3 i j k 3 5 I need to sum up the last 2 columns and make a data file...How i can do that. a b c 1 2 e f g 2 3 i j k 3 5... (8 Replies)
Discussion started by: bobprabhu
8 Replies

9. Shell Programming and Scripting

Help with awk logic

I want to print lines that have "IND" or "ind" or nothing in field 2 or 3 file: output needed: Code i wrote: nawk -F"," '{if(tolower($2||$3) ~"ind"||"")print}' file Help is appreciated (3 Replies)
Discussion started by: pinnacle
3 Replies

10. Shell Programming and Scripting

need a logic for awk programming

Hello Friends, I have a txt file like below //*Init Start Reg(read,12'h42E,16'h0000); Nop(5628.5); //*Init End //*Main Start Reg(read,12'h42E,16'h0000); Nop(5628.5); //*Main End I want to calculate the values between //* Init Start & //* Init End And //*Main Start & //*Main... (5 Replies)
Discussion started by: user_prady
5 Replies
Login or Register to Ask a Question