Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Print each output of loop in new column using awk or shell Post 302822237 by pamu on Monday 17th of June 2013 07:20:26 AM
Old 06-17-2013
Code:
awk '/^a/{if(x>max){max=x};x=1} 
{A[x++]=A[x]?A[x] OFS $0 : $0} 
END{for(i=1;i<max;i++){print A[i]}}' OFS="\t" file

 

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Loop column output

I need help in what to do with a bash script? I'm trying to run a command to output the data from a table and then insert it into commands. Looping for each row of data. For example the output data from a table: 10 John house 20 Jane apt 30 Joe townhomeThen I need to take the output... (1 Reply)
Discussion started by: handband2
1 Replies

2. Shell Programming and Scripting

find expression with awk in only one column, and if it fits, print whole column

Hi. How do I find an expression with awk in only one column, and if it fits, then print that whole column. 1 apple oranges 2 bannanas pears 3 cats dogs 4 hesaid shesaid echo "which number:" read NUMBER (user inputs number 2 for this example) awk " /$NUMBER/ {field to search is field... (2 Replies)
Discussion started by: glev2005
2 Replies

3. Shell Programming and Scripting

loop in awk - column max for each column

Hello all, this should really be easy for you... I need AWK to print column maxima for each column of such input: Input: 1 2 3 1 2 1 1 3 2 1 1 2 Output should be: 2 2 3 3 This does the sum, but i need max instead: { for(i=1; i<=NF; i++) sum +=$i } END {for(i=1; i in sum;... (3 Replies)
Discussion started by: irrevocabile
3 Replies

4. Shell Programming and Scripting

Print a column with the name of the output file

I have n files and I am using cat to combine them in to one. Before that simply add the name of the output file to 4th column and then print the output. Is it possible ? input1 chr start end name 0 + key input2 chr start end name 0 + key inputn... (1 Reply)
Discussion started by: quincyjones
1 Replies

5. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

Print for loop variable in output too

Hi, This is my input file cat input chr1:100-200 chr1:220-300 chr1:300-400 Now, I would like to run a program that will take each of the input record for i in `cat input`; do program $i | wc -l;done the output will be something like 10 20 30 But, I would like to print the... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

7. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

8. Shell Programming and Scripting

Print awk output in same line ,For loop

My code is something like below. #/bin/bash for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'` do echo $i ORACLE_SID=`echo $line | awk '{print $2}'` USERNAME=`echo $line | awk '{print $1}'` done ============= But... (3 Replies)
Discussion started by: tapia
3 Replies

9. Shell Programming and Scripting

Print loop output on same line dynamically

Hi, I am trying to print copy percentage completion dynamically by using the script below, #!/bin/bash dest_size=0 orig_size=`du -sk $sourcefile | awk '{print $1}'` while ; do dest_size=`du -sk $destfile | awk '{print $1}'` coyp_percentage=`echo "scale=2; $dest_size*100/$orig_size"... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

10. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies
MAX(3)									 1								    MAX(3)

max - Find highest value

SYNOPSIS
mixed max (array $values) DESCRIPTION
mixed max (mixed $value1, mixed $value2, [mixed $...]) If the first and only parameter is an array, max(3) returns the highest value in that array. If at least two parameters are provided, max(3) returns the biggest of these values. Note Values of different types will be compared using the standard comparison rules. For instance, a non-numeric string will be com- pared to an integer as though it were 0, but multiple string values will be compared alphanumerically. The actual value returned will be of the original type with no conversion applied. PARAMETERS
o $values - An array containing the values. o $value1 - Any comparable value. o $value2 - Any comparable value. o $... - Any comparable value. RETURN VALUES
max(3) returns the parameter value considered "highest" according to standard comparisons. If multiple values of different types evaluate as equal (e.g. 0 and 'abc') the first provided to the function will be returned. EXAMPLES
Example #1 Example uses of max(3) <?php echo max(2, 3, 1, 6, 7); // 7 echo max(array(2, 4, 5)); // 5 // The string 'hello' when compared to an int is treated as 0 // Since the two values are equal, the order they are provided determines the result echo max(0, 'hello'); // 0 echo max('hello', 0); // hello // Here we are comparing -1 < 0, so 'hello' is the highest value echo max('hello', -1); // hello // With multiple arrays of different lengths, max returns the longest $val = max(array(2, 2, 2), array(1, 1, 1, 1)); // array(1, 1, 1, 1) // Multiple arrays of the same length are compared from left to right // so in our example: 2 == 2, but 5 > 4 $val = max(array(2, 4, 8), array(2, 5, 1)); // array(2, 5, 1) // If both an array and non-array are given, the array will be returned // as comparisons treat arrays as greater than any other value $val = max('string', array(2, 5, 7), 42); // array(2, 5, 7) // If one argument is NULL or a boolean, it will be compared against // other values using the rule FALSE < TRUE regardless of the other types involved // In the below example, -10 is treated as TRUE in the comparison $val = max(-10, FALSE); // -10 // 0, on the other hand, is treated as FALSE, so is "lower than" TRUE $val = max(0, TRUE); // TRUE ?> SEE ALSO
min(3), count(3). PHP Documentation Group MAX(3)
All times are GMT -4. The time now is 08:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy