california Canada conference Conferences database db db2 DB2 pureXML development eclipse fall flickr google ibm Internet it java jdbc Joomla Linux mapping Open Source Other perl Personal Photography Portugal programming purexml rails rogers ruby shipment Software software-testing sql sqlj Tech toronto tpmg Travel twiki USA xml yahoo

How to replace text in a file with huge lines

Tags: , , , , , , , ,

This is my problem: I have a huge xml file (150MB), in which I want to rename some of the node names. Conisder the example:

<root><prefix_name1>1</prefix_name1><prefix_name2>text</prefix_name2></root>

The creators of this document were not aware of namespaces, so they decided to use different prefixes in the element names in the documents created. My goal is to rename all the tags with prefix removing the "prefix_" part of the name. The solution looked simple, but it isn’t.

To begin with, I tried a sed, using the argument "s/prefix_//g". This didn’t work, because in AIX sed only accepts up to 4096 bytes per line (I read somewhere that this doesn’t happen with some sed versions, but I couldn’t spend the whole day trying versions of sed). Using perl also resulted in Out of memmory errors (I’ve just very basic perl knowledge, so there may be a way of handling such big lines).

So, I had to come up with a set of steps to do this change and maintain the file in it’s original format (all contents in one line). The steps where:

  •  used the tr utility to translate all ">" characters into a new line (a new > is printed before the replaced char) using tr  ‘>’ ‘\012′ < $1  | while read line; do echo "${line}>"  >> $1.new done.
  • rename the tags by removing the prefix. Either use sed or perl with the replacement pattern "s/prefix_//g".
  • delete all the "\n" (newline chars) from the current file, to get back to the one liner format. Used perl to read from one file and write to other applying "s/\n//g" to the content.

I’m sure that this is not the best solution, and there must be some utility out there that I can use so, if you have any idea, just leave a comment.

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.11_1134]
Rating: 0 (from 0 votes)

Popularity: 3% [?]

1 Comment »

Thinkpad not charging the battery

Tags: , , , , , , , ,

If you have a Thinkpad and you happen to run into the state where your laptop doesn’t charge the battery anymore, here are the common solutions for the problem:

  1. shutdown your laptop, remove the battery and unplug the power cable. Hold the power button for 10 seconds. Plug battery and power cable and power on your laptop.
  2. update the BIOS.
  3. send the laptop for service :-)
Although the 1st option may look funny, it works indeed. It didn’t work in my case, but it was the first suggestion from other people that had run into the problem and fixed it by using this trick. It is also one of the first things you get asked to do when you call customer service. One of the bad things about laptops is that everything is integrated in the system board, so even if you have just a small problem, the complete system board needs to be replaced. Since the system board is the most requested part, sometimes the wait can be longer.
VN:F [1.9.11_1134]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.11_1134]
Rating: 0 (from 0 votes)

Popularity: 2% [?]

2 Comments »