Parsing Column Values in Row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing Column Values in Row
# 1  
Old 04-28-2014
Tools 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 & before beginning of xxxxxxxxx patern there will be a new line

Thanks in advance for any suggestions ...

Desired Op

Code:
1412 91175
1234 98760
1400 09167

Raw Data

Code:
 xxxxxxxxx(H'0001)=H'0001
 xxxxxxxxx(H'0002)=H'0004
 xxxxxxxxx(H'0003)=H'0001
 xxxxxxxxx(H'0004)=H'0002
 TRARE   (B) VAR H'00 A063:H'111=H'0080
 yyyyyyyyy(H'0001)=H'0009
 yyyyyyyyy(H'0002)=H'0001
 yyyyyyyyy(H'0003)=H'0001
 yyyyyyyyy(H'0004)=H'0007
 yyyyyyyyy(H'0005)=H'0005
  xxxxxxxxx(H'0001)=H'0001
 xxxxxxxxx(H'0002)=H'0002
 xxxxxxxxx(H'0003)=H'0003
 xxxxxxxxx(H'0004)=H'0004
 TRARE   (B) VAR H'00 A063:H'111=H'0080
 yyyyyyyyy(H'0001)=H'0009
 yyyyyyyyy(H'0002)=H'0008
 yyyyyyyyy(H'0003)=H'0007
 yyyyyyyyy(H'0004)=H'0006
 yyyyyyyyy(H'0005)=H'0000
  xxxxxxxxx(H'0001)=H'0001
 xxxxxxxxx(H'0002)=H'0004
 xxxxxxxxx(H'0003)=H'0000
 xxxxxxxxx(H'0004)=H'0000
 TRARE   (B) VAR H'00 A063:H'111=H'0080
 yyyyyyyyy(H'0001)=H'0000
 yyyyyyyyy(H'0002)=H'0009
 yyyyyyyyy(H'0003)=H'0001
 yyyyyyyyy(H'0004)=H'0006
 yyyyyyyyy(H'0005)=H'0007


Last edited by Don Cragun; 04-28-2014 at 06:22 AM.. Reason: Add CODE tags.
# 2  
Old 04-28-2014
Can you please elaborate?
# 3  
Old 04-28-2014
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

This User Gave Thanks to RudiC For This Post:
# 4  
Old 04-28-2014
I have mentioned the Raw data to be processed & the Output too..

Let me know if any other info req ..

BR//
# 5  
Old 04-28-2014
Hi RudiC

could you please explain above caommand?
# 6  
Old 04-28-2014
Single Line output

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

The Output is a single line output wrapped by Text limit, not readable.

I tried to make it readable by using {printf "%s\n",O}, but no change in Output.
# 7  
Old 04-28-2014
try using 'nawk' instead of 'awk'
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