1753789 Members
7550 Online
108799 Solutions
New Discussion юеВ

Re: format ouput file

 
Anand_30
Regular Advisor

format ouput file

Hi,

I have created an output file which is attached to this message. I want to format the output. It is a SQL query output and i want each record to come in a single line and not get wrapped as the case now.

Can anyone please help me.

Thanks,
Andy
6 REPLIES 6
Mel Burslan
Honored Contributor

Re: format ouput file

without knowing how you get this data, it is hard to guess why it came like this but, it very much seems like a screen dump from a 80 column terminal emulator and the emulator may have included the linebreaks in it.

suggestion is to run your sql query and redirect output to a file something like

sql select * from blah...blah > /tmp/sqldump

then transfer this file to your workstation using ftp rather than screen capture or log capture from a terminal emulator

Hope this helps
________________________________
UNIX because I majored in cryptology...
Anand_30
Regular Advisor

Re: format ouput file

Thanks for the reply...I wrote a script which connects to sql using isql and then executes the query and gets this ouput:

isql -U[user] -P[password] << EOF > output

Now i need to format this ouput so that it is better readable.

-Andy



Mel Burslan
Honored Contributor

Re: format ouput file

if you are generating the sql output in unix environment then trying to view it in DOS/Windows, you can try one of the free unix2dos utilities that you can download from any decent freeware site. CR - to - CR/LF conversion makes a document a lot easier to read in windows :)
________________________________
UNIX because I majored in cryptology...
Stuart Browne
Honored Contributor

Re: format ouput file

What are the values of the environment variable 'COLUMNS', and the stty value of 'cols' ?

Simply: 'echo $COLUMNS' and 'stty -a' to get them.

I'm picking that one or the other is set to 80, or that 'isql' defaults to wrap-at-80. Try bumping these values up. See what the result is.
One long-haired git at your service...
Anand_30
Regular Advisor

Re: format ouput file

The column value is 154. But i am using a terminal emulater that has columns set to 80.

Regards
Anand
Hein van den Heuvel
Honored Contributor

Re: format ouput file


This problem really should be solved in SQL.
In Oracle SQLplus lingo you would need
SET LINESIZE 999;
and probably lots of
COLUMN xxx FORMAT Ann
for example
COLUMN VENDER FORMAT A20;

Your chance to learn more SQL!

If you have to live with the file you have today, just push it through PERL or AWK (on PC or Unix box.
For example:


C:\>perl -e "<>;<>;while (<>) {for ($i=0;$i<4;$i++){chop; $_.=<>}print}" narrow.txt > wide.txt


This says...
- read and forget twice.
- main loop reading a line.
- subloop 4 times chopping of the last character (newline) and appending (the .=) an additional line.
- print (the default it to print $_)
- end main loop

Hein.