Sponsored Content
Top Forums Shell Programming and Scripting cannot get logic for concatenation awk Post 302148887 by user_prady on Tuesday 4th of December 2007 02:53:27 AM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
ARRAY_SPLICE(3) 							 1							   ARRAY_SPLICE(3)

array_splice - Remove a portion of the array and replace it with something else

SYNOPSIS
array array_splice (array &$input, int $offset, [int $length], [mixed $replacement = array()]) DESCRIPTION
Removes the elements designated by $offset and $length from the $input array, and replaces them with the elements of the $replacement array, if supplied. Note that numeric keys in $input are not preserved. Note If $replacement is not an array, it will be typecast to one (i.e. (array) $parameter). This may result in unexpected behavior when using an object or NULL$replacement. PARAMETERS
o $input - The input array. o $offset - If $offset is positive then the start of removed portion is at that offset from the beginning of the $input array. If $offset is negative then it starts that far from the end of the $input array. o $length - If $length is omitted, removes everything from $offset to the end of the array. If $length is specified and is positive, then that many elements will be removed. If $length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. If $length is specified and is zero, no elements will be removed. Tip: to remove everything from $offset to the end of the array when $replacement is also specified, use count($input) for $length. o $replacement - If $replacement array is specified, then the removed elements are replaced with elements from this array. If $offset and $length are such that nothing is removed, then the elements from the $replacement array are inserted in the place specified by the $offset. Note that keys in replacement array are not preserved. If $replacement is just one element it is not necessary to put array() around it, unless the element is an array itself, an object or NULL. RETURN VALUES
Returns the array consisting of the extracted elements. EXAMPLES
Example #1 array_splice(3) examples <?php $input = array("red", "green", "blue", "yellow"); array_splice($input, 2); // $input is now array("red", "green") $input = array("red", "green", "blue", "yellow"); array_splice($input, 1, -1); // $input is now array("red", "yellow") $input = array("red", "green", "blue", "yellow"); array_splice($input, 1, count($input), "orange"); // $input is now array("red", "orange") $input = array("red", "green", "blue", "yellow"); array_splice($input, -1, 1, array("black", "maroon")); // $input is now array("red", "green", // "blue", "black", "maroon") $input = array("red", "green", "blue", "yellow"); array_splice($input, 3, 0, "purple"); // $input is now array("red", "green", // "blue", "purple", "yellow"); ?> Example #2 array_splice(3) examples The following statements change the values of $input the same way: <?php array_push($input, $x, $y); array_splice($input, count($input), 0, array($x, $y)); array_pop($input); array_splice($input, -1); array_shift($input); array_splice($input, 0, 1); array_unshift($input, $x, $y); array_splice($input, 0, 0, array($x, $y)); $input[$x] = $y; // for arrays where key equals offset array_splice($input, $x, 1, $y); ?> SEE ALSO
array_slice(3), unset(3), array_merge(3). PHP Documentation Group ARRAY_SPLICE(3)
All times are GMT -4. The time now is 10:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy