Visit Our UNIX and Linux User Community


Transpose using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Transpose using awk
# 1  
Old 07-21-2009
Transpose using awk

I have a requirement to transpose the below xml which is in a text file on unix:

Code:
<?xml version="1.0" ?>
<REQUEST>
<ID>XXX</ID>
<TIMESTAMP>20090720062610</TIMESTAMP>
<FLAG>Y</FLAG>
<TO_FLAG>Y</TO_FLAG>
</REQUEST>

to

Code:
<?xml version="1.0" ?><REQUEST><ID>XXX</ID><TIMESTAMP>20090720062610</TIMESTAMP><FLAG>Y</FLAG><TO_FLAG>Y</TO_FLAG></REQUEST>

the current awk command that i am using provides the output truncating all the spaces as below, the spaces in the tag
Code:
<?xml version="1.0" ?>

are removed:

Code:
<?xmlversion="1.0"?><REQUEST><ID>XXX</ID><TIMESTAMP>20090720062610</TIMESTAMP><FLAG>Y</FLAG><TO_FLAG>Y</TO_FLAG></REQUEST>

the awk command i am using:
Code:
awk '$1=$1' RS='' OFS='' test_trans.txt > SEQS_TRANS_test.txt


Help appreciated , Thanks in Advance.

Last edited by vgersh99; 07-21-2009 at 11:12 AM.. Reason: code tags, PLEASE!
# 2  
Old 07-21-2009
Edit your post and use CODE tags when displaying code, data or logs to enhance readability and to preserve formatting like indention etc.,ty.
# 3  
Old 07-21-2009
Try:
Code:
awk '{printf $0} END {printf "\n"}' file

# 4  
Old 07-21-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 5  
Old 07-21-2009
Moderators, I will keep in mind not to post those again.

Thanks for the response rakeshawasti......

But there is a space at every new line.

like below:

Code:
[?xml version="1.0" ?][REQUEST] [ID>497[/ID] [TIMESTAMP]20090720062610[TIMESTAMP] [FLAG]Y[/FLAG] [TO_FLAG]Y[/TO_FLAG][/REQUEST]

can we eliminate those spaces as well.

Last edited by vgersh99; 07-21-2009 at 01:22 PM.. Reason: code tags, PLEASE!
# 6  
Old 07-21-2009
Try this:

Code:
awk '1' ORS= file

If you want a newline at the end:

Code:
awk '{print} END{print "\n"}' ORS= file

# 7  
Old 07-21-2009
Still struggling with it, i am posting a complete picture of what i am facing trouble with......

The XML available for me is in the below format:
Code:
<?xml version="1.0" ?>
<REQUEST>
 <ID>874</ID>
 <TIMESTAMP>20090720062610</TIMESTAMP>
 <FLAG>Y</FLAG>
 <TO_FLAG>Y</TO_FLAG>
</REQUEST>
 
<?xml version="1.0" ?>
<REQUEST>
 <ID>000</ID>
 <TIMESTAMP>20090720061218</TIMESTAMP>
 <FLAG>Y</FLAG>
 <TO_FLAG>Y</TO_FLAG>
</REQUEST>

I need that to be transposed into below:
Code:
<?xml version="1.0" ?><REQUEST><ID>874</ID><TIMESTAMP>20090720062610</TIMESTAMP><FLAG>Y</FLAG><TO_FLAG>Y</TO_FLAG></REQUEST>
<?xml version="1.0" ?><REQUEST><ID>000</ID><TIMESTAMP>20090720061218</TIMESTAMP><FLAG>Y</FLAG><TO_FLAG>Y</TO_FLAG></REQUEST>

As mentioned in the above every new XML starts with the tag
Code:
<?xml version="1.0" ?>

Also something to be noted is that the XML tag contains spaces which should stay.
Code:
<?xml version="1.0" ?>

Thanks in Advance.

Previous Thread | Next Thread
Test Your Knowledge in Computers #261
Difficulty: Easy
On 8 June 1954, Alan Turing's housekeeper found him dead at the age of 41; a suicide by cyanide poisoning.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Transpose table with awk

I am trying to format the table below to the output input: cand week sub1 sub2 sub3 sub4 joe 1 94.19 70.99 43.93 60.14 joe 2 94.07 51.02 41.07 38.92 joe 3 26.24 30.95 44.56 67.67 joe 4 72.36 60.92 40.78 83.25 joe 5 51 70.01 44.66 82.22... (7 Replies)
Discussion started by: aydj
7 Replies

2. Shell Programming and Scripting

Transpose using awk

Hi Friends, Very urgent requirement please do needful ASAP.. Input: |1||1|1||1|3||3|2||2|4||4|2||2|3||3|NA||0|5||5|NA||0|4||4|3||3 output: |1||1 |1||1 |3||3 |2||2 |4||4 |2||2 |3||3 |NA||0 |5||5 (4 Replies)
Discussion started by: bharat1211
4 Replies

3. Shell Programming and Scripting

Transpose data as rows using awk

Hi I have below requirement, need help One file contains the meta data information and other file would have the data, match the column from file1 and with file2 and extract corresponding column value and display in another file File1: CUSTTYPECD COSTCENTER FNAME LNAME SERVICELVL ... (1 Reply)
Discussion started by: ravlapo
1 Replies

4. Shell Programming and Scripting

awk to transpose every 7 rows into columns

input: a1 a2 a3 a4 a5 a6 a7 b1 b2 b3 .. b7 .. z1 .. z7 (12 Replies)
Discussion started by: ux4me
12 Replies

5. Shell Programming and Scripting

Transpose column to row - awk

Hi there, I have a small csv file example below: source,cu_001,cu_001_volume,cu_001_mass,cu_002,cu_002_volume,cu_002_mass,cu_003,cu_003_volume,cu_003_mass ja116,1.33,3024000,9374400,1.54,3026200,9375123,1.98,3028000,9385512 I want to transpose columns to rows starting at the second... (3 Replies)
Discussion started by: theflamingmoe
3 Replies

6. Shell Programming and Scripting

Complex transpose awk script

Hello to all in forum, Maybe an awk expert could help me with this complex task for me. I have the input shown below and I would like to get the output as follow: - I would like the output separated by commas. - The header is fixed and will be the same always. - For the lines containing... (22 Replies)
Discussion started by: Ophiuchus
22 Replies

7. Shell Programming and Scripting

awk transpose rows to column

Need to transpose in awk rows to column like this: input: A1,6,5,4 3,2,1, A2,8,7,9,10,11,12,13,14 A3,1,2,3,5,7,8,9 A4,9,4,8,1,5,3, output: A1,1 A1,2 A1,4 ... A2,7 A2,8 ... A3,1 A3,2 ... A4,1 A4,3 (5 Replies)
Discussion started by: sdf
5 Replies

8. Shell Programming and Scripting

How can i transpose this rerult by using awk?

From>>> ATOM 1 ca 2 o 3 h 4 h 5 o dE/dx 0.2057422D-01 0.2463722D-01-0.1068047D-01-0.1495280D-01-0.3725362D-02 dE/dy -0.7179106D-02-0.1554542D-01 0.1016889D-01 0.3268502D-02-0.4888578D-01 dE/dz -0.5600872D-02 0.3110649D-01-0.4088230D-02-0.2295107D-01-0.2832048D-01 ATOM 6 h 7 h 8 o 9 h 10 h... (1 Reply)
Discussion started by: wanchem
1 Replies

9. Shell Programming and Scripting

How to transpose a table of data using awk

Hi. I have this data below:- v1 28 14 1.72414 1.72414 1.72414 1.72414 1.72414 v2 77 7 7.47126 6.89655 6.89655 6.89655 6.89655 v3 156 3 21.2644 21.2644 20.6897 21.2644 20.6897 v4 39 3 1.72414 1.72414 1.72414 1.72414 1.72414 v5 155 1 21.2644 23.5632 24.1379 23.5632 24.1379 v6 62 2 2.87356... (2 Replies)
Discussion started by: ahjiefreak
2 Replies

10. Shell Programming and Scripting

How to transpose data elements in awk

Hi, I have an input data file :- Test4599,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,2,Rain Test90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,Not Rain etc.... I wanted to transpose these data to:-... (2 Replies)
Discussion started by: ahjiefreak
2 Replies

Featured Tech Videos