Parsing Column Values in Row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing Column Values in Row
# 8  
Old 04-28-2014
Quote:
Originally Posted by RudiC
Try sth like (untested)
Code:
awk '/xxxxxxxxx/ {if (L) {print O; O=""; L=0}; O=O substr($0, length($0))}
     /yyyyyyyyy/ {if (!L) {O=O" "; L=1}; O=O substr($0, length($0))}
     END         {print O}
    ' file

Hi Rudic,
can u plz explain the Code, i am not able to make out the meaning of L & Os ...Smilie

BR//
# 9  
Old 04-28-2014
L is a variable he sets himself, to turn printing on and off.

O is a variable which is all the data you want jammed together.
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 04-28-2014
Thanks ...Solved

Quote:
Originally Posted by Corona688
L is a variable he sets himself, to turn printing on and off.

O is a variable which is all the data you want jammed together.
Rudic's code worked, being new to awk, i thought L & O to be some sort of Inbuilt variable carrying some special meaningSmilie.

Thanks to both Rudic & Corona for Support ...Smilie
# 11  
Old 04-29-2014
Quote:
Originally Posted by Makarand Dodmis
Hi RudiC

could you please explain above caommand?
Code:
awk '/xxxxxxxxx/ {if (L) {print O; O=""; L=0}; O=O substr($0, length($0))}      # for all lines having the xxx pattern
                                                                                #   if L(ogical) is set, print the output line, clear it, reset L
                                                                                #   collect last char into O(utput) variable
     /yyyyyyyyy/ {if (!L) {O=O" "; L=1}; O=O substr($0, length($0))}            # for yyy pattern
                                                                                #   if not L (= first yyy pattern), add a space for separator to O, set L 
                                                                                #   collect last char as well
     END         {print O}                                                      # print the O(utput) for the last record
    ' file

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

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

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

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

6. Shell Programming and Scripting

parsing df column values

Hi all, I need to run df, and parse the value under column of "Mounted on" For instance, my df is Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 4881344 4106460 526924 89% / none 245164 220 244944 1% /dev... (6 Replies)
Discussion started by: peuceul
6 Replies

7. Shell Programming and Scripting

Arrange values of a column in row

HI, I need to arrange values of a colum in row. e.g. input file : Alpha<>123 AAAA<>6754 Beta<>456 BBBB<>63784 CCC<>783 Gama<>789 Alpha<>555 AAAA<>6754 BBBB<>63784 Beta<>666 CCC<>783 Gama<>888 (9 Replies)
Discussion started by: The_Archer
9 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