Transpose using awk

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

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

to

<?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

<?xml version="1.0" ?>

are removed:

<?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:

awk '$1=$1' RS='' OFS='' test_trans.txt > SEQS_TRANS_test.txt

Help appreciated , Thanks in Advance.

Edit your post and use CODE tags when displaying code, data or logs to enhance readability and to preserve formatting like indention etc.,ty.

Try:

awk '{printf $0} END {printf "\n"}' file

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

```text
 and 
```

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

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:

[?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.

Try this:

awk '1' ORS= file

If you want a newline at the end:

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

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:

<?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:

<?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

<?xml version="1.0" ?>

Also something to be noted is that the XML tag contains spaces which should stay.

<?xml version="1.0" ?>

Thanks in Advance.

nawk '
   BEGIN {
      RS=FS=OFS=""
   }
   {for(i=2;i<=NF;i++) gsub(" ", "", $i); print}' myFile

try..

-bash-3.2$ cat test
<?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>
-bash-3.2$ echo `cat test` | sed 's/> </></g'
<?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>
-bash-3.2$

ryandegreat....thanks for the code, but i need the every <xml version...> tag in new line.

Assuming the xml tag format will remain ( as described ) constant: <?xml + spaces + version="Nr-dot-Nr" + spaces + ?> , this might be enough:

awk '/^<\?xml( |\t)+version="[0-9]+\.[0-9]+"( |\t)+\?>$/ && NR>1{ printf RS $0; next}
      NF { sub(/^[ \t]+/,""); print } END{ print RS }'   ORS=   filename

Output:

<?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>

Try this:

awk 'BEGIN{RS=ORS="\n\n"} $1=$1' file

Regards

try this from franklin

awk 'BEGIN{RS=ORS="\n\n"} $1=$1' test | grep . | sed 's/> </></g'

or

echo `cat test`| sed -e 's|</REQUEST> |&\n|g' -e 's|> <|><|g'
 
sed 's/^ *//' file.xml | tr -d '\x0A'