View Single Post
  #2   (View Single Post)  
Old 19th March 2009
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,319
Default

Quote:
Originally Posted by gosha View Post
I have a table with the following sample values:
Code:
column1     column2     column3     column4
1           2           a           b
1           2           c           d
1           2           e           f
is there a way to get this:
Code:
column1     column2     column3     column4
1           2           a           b
                        c           d
                        e           f
It is unclear why the first two columns change, but the other two remain the same from the first representation to the second. If this is simply an oversight, yes, sed(1) can be used to reformat it, but personally, I would find this akin to extracting my own teeth with a pair of pliers.

With whatever database you are using, you should have some form of administrative console which allows you to interact with the database by typing in SQL commands. The output of SELECT statements may be formatted well enough for your needs. If you need more control, you should be able to capture the output of the administrative console, & manipulate the output with awk(1), perl(1), or a host of other scripting tools.

If logic is required to move from the first representation above to the second, I would highly recommend awk, perl, et. al.. sed will not be able to perform sophisticated logic.

In particular, if you are wanting to format columns, look at the printf() function available in any of the scripting languages (even in Python...) as this will allow you to fix the column size even when the text in the column varies.
Reply With Quote