Arrange values of a column in row

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arrange values of a column in row
# 8  
Old 06-15-2011
awk '/Alpha/ { a=$0;next } /Beta/ { a=a"|"$0;next } /Gama/ {a=a"|"$0; print a}' input_file

I am expecting there will be a matching "Gama" in the end and the order also wil be remain same
# 9  
Old 06-15-2011
Open logic Shell version. Assuming you have shell which supports echo with \c (no linefeed). If not, use "echo -n" or printf.

cat file.txt | while read line
        case "$line" in
        Alpha*) echo "${line} | \c"
        Beta*)  echo "${line} | \c"
        Gama*)  echo "${line} |"

Alpha<>123 | Beta<>456 | Gama<>789 |
Alpha<>555 | Beta<>666 | Gama<>888 |

# 10  
Old 06-15-2011
use below.

gawk '/Alpha/||/Beta/{s= s ? s"|"$0 : $0 }/Gama/{print s"|"$0 ; s="" }' infile.txt


Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to add one to each row values and keep it after the value in the column?

Dear Folks Hello I have a column of numbers, say: 26 79 68 I want to add one to each row value and get this desire column: 26 27 79 80 68 69 (6 Replies)
Discussion started by: sajmar
6 Replies

2. UNIX for Dummies Questions & Answers

Unique values in a row sum the next column in UNIX

Hi would like to ask you guys any advise regarding my problem I have this kind of data file.txt 111111111,20 111111111,50 222222222,70 333333333,40 444444444,10 444444444,20 I need to get this file1.txt 111111111,70 222222222,70 333333333,40 444444444,30 using this code I can... (6 Replies)
Discussion started by: reks
6 Replies

3. Shell Programming and Scripting

Parsing Column Values in Row

Hi , I have been trying to write a awk script which will have the following Output 1. Append the last Characters of the lines matching pattern xxxxxxxxx & then a space & then Append the last Characters of the lines matching pattern yyyyyyyyy 2. the process will continue till end of file &... (10 Replies)
Discussion started by: newageBATMAN
10 Replies

4. Shell Programming and Scripting

Move values from column to row

Hello guys. Please can you help me with this.. Thanks in advance:b: Input file 2134 6371 N 2150 6371 M 2166 6371 S 2138 6417 N 2154 6417 M 2170 6417 S 2157 6603 N 2173 6603 M 2189 6603 S desired uotput 6371 2134N 2150M 2166S 6417 2138N 2154M 2170S... (2 Replies)
Discussion started by: jiam912
2 Replies

5. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Deleting row if all column values are a particular string

Hello, I have a very large file for which I would like to remove all rows for which the value of columns 2-5 is zero. For instance I would like this file: contig1, 0, 0, 0, 0 contig2, 1, 3, 5, 0 contig3, 0, 0, 0, 0 contig4, 0, 5, 6, 7 To become this file: contig2, 1, 3, 5,0 ... (17 Replies)
Discussion started by: mouchkam
17 Replies

7. Shell Programming and Scripting

Find and replace duplicate column values in a row

I have file which as 12 columns and values like this 1,2,3,4,5 a,b,c,d,e b,c,a,e,f a,b,e,a,h if you see the first column has duplicate values, I need to identify (print it to console) the duplicate value (which is 'a') and also remove duplicate values like below. I could be in two... (5 Replies)
Discussion started by: nuthalapati
5 Replies

8. Shell Programming and Scripting

Converting values in a ROW to COLUMN

Hi All, I needd to convert values in a row to a column. eg: Input is as: value1,value2,value3,value4,.........,value N Required Output: Value1 Value2 Value3 . . . Value N Please help.... (3 Replies)
Discussion started by: sambaman
3 Replies

9. Shell Programming and Scripting

Convert column values into row

hi, I have a requirement where in I read the values from a file using awk. The resulting data should be converted into row format from column format. For ex: My log file login.lst contains the following SERVER1 DB1 SERVER2 DB2 SERVER3 DB3 SERVER4 DB4 I use awk to grep only the server... (6 Replies)
Discussion started by: senthil3d
6 Replies

10. Shell Programming and Scripting

Concatenating column values with unique id into single row

Hi, I have a table in Db2 with data say id_1 phase1 id_1 phase2 id_1 phase3 id_2 phase1 id_2 phase2 I need to concatenate the values like id_1 phase1,phase2,phase3 id_2 phase1,phase2 I tried recursive query but in vain as the length of string to be concatenated in quite long. ... (17 Replies)
Discussion started by: jsaravana
17 Replies
Login or Register to Ask a Question