Shell Script Problems, Lose formatting when copy pasting from formatted file.

Hello,

I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating!

Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a column of information each. I merge them all into one output file, with a separate column for each input file using:

paste data data2 data3 data4 data5 data6 data7 | awk  '{printf "%-12s%-12s%-12s%-12s%-12s%-12s%-12s\n", $1, $2, $3, $4, $5,  $6, $7}' > output

The result looks good in the output file and when the output is displayed in the Terminal, but when I copy paste from the output file into another file the columns become all jumbled.

I've also tried:

pr -m -t data data2 data3 data4 data5 data6 data7 >| expand > output

I have no idea what to do to solve this, any help would be greatly appreciated.

What's the meaning of "copy paste", not by command cp?

Thanks for the reply,

No not by the command cp. I can't use cp in this case.

I was thinking maybe I can make the columns by inserting spaces somehow to hold the columns in place, but I'm not sure how to go about it. This is how the output ends up:

TUE      WED        THU          FRI    SAT      SUN        MON
16      17        18          19    20      19        17
Showers      Morning   Mostly    Mostly    Afternoon Numerous  Rain
Early.      Clouds.   Sunny.    Sunny.    Clouds.      Showers.  Early.
Mostly      Mild.        Mild.     Mild.    Mild.      Mostly    Morning
Sunny.                  Breezy.    Breezy.      Cloudy.   Clouds.
Cool.                          Mild.        Cool.
Windy.                          Breezy.   Breezy.

But when it is displayed in the terminal it looks perfect. Is there a way to dynamically assign spaces to hold the formatting in place?

This is a very good suggestion (from the forum rules):

I think it is a simple font selection issue in the application window.

Please try using a non-proportional (fixed width) true type font.

OK

Thanks for the suggestion ananthap but it didn't work.

---------- Post updated at 10:09 PM ---------- Previous update was at 10:06 PM ----------

Here you go yazu:

Hardware Overview:

      Model Name: MacBook
      Model Identifier: MacBook6,1
      Processor Name: Intel Core 2 Duo
      Processor Speed: 2.26 GHz
      Number Of Processors: 1
      Total Number Of Cores: 2
      L2 Cache: 3 MB
      Memory: 5 GB
      Bus Speed: 1.07 GHz
      Boot ROM Version: MB61.00C8.B00
      SMC Version (system): 1.51f53
System Software Overview:

      System Version: Mac OS X 10.6.5 (10H574)
      Kernel Version: Darwin 10.5.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Secure Virtual Memory: Enabled
      64-bit Kernel and Extensions: No
      Time since boot: 1 day12:44

:slight_smile: Well, Mac OS X would be enough (I thought maybe you are on windows with PuTTY or something like).
Do you get the "output" file on your local computer or you use some remote connection? If on the local one then why do you paste from terminal window and not from some editor opening your "output"?

Yes the file is here on the local computer. I'm not copy pasting from the terminal window but from the output file. The output file is formatted correctly, nice neat columns, but when I try and copy from it and paste into another file it loses all formatting. I was hoping I could introduce spaces to separate the rows, but it would need to be done via some script as the data in the file will change everyday.

I'm trying to get this to display on my desktop with geektool, but it looks like geektool mangles the formatting in the exact same way that copy paste does. So I think it if I can solve the problem with copy paste, I will have solved the problem in geek tool. At least I hope...

Mysteriously enough...
What the output of this command:

paste -d' ' data data2 data3 data4 data5 data6 data7 | 
awk  '{printf "%-12s%-12s%-12s%-12s%-12s%-12s%-12s\n", $1, $2, $3, $4, $5,  $6, $7}' |
od -c -tx1 | head 

It comes out like this:

0000000    T   U   E                                       W   E   D    
           54  55  45  20  20  20  20  20  20  20  20  20  57  45  44  20
0000020                                    T   H   U                    
           20  20  20  20  20  20  20  20  54  48  55  20  20  20  20  20
0000040                    F   R   I                                    
           20  20  20  20  46  52  49  20  20  20  20  20  20  20  20  20
0000060    S   A   T                                       S   U   N    
           53  41  54  20  20  20  20  20  20  20  20  20  53  55  4e  20
0000100                                    M   O   N                    
           20  20  20  20  20  20  20  20  4d  4f  4e  20  20  20  20  20

Except it gets a bit mangled when I paste it in here.

I've been playing around a bit and discovered that the formatting is retained when I put the output into a plain text file (even when copy pasting) but it still appears mangled in geektool. It must have something to do with how geektool reads files or something. Hopefully there is a workaround involving spaces or invisible characters or something...

Everything is OK. It's better to use something like 'head -n30' to see that new lines are on place but I think there won't be any problem too.
Unfortunately I don't have Mac and I know nothing about geektool and other quirks on this system. :frowning:

Haha no problem yazu, thanks for your help all the same. I'm thinking it probably has something to do with geektool mangling everything. Quite annoying really because I spent ages figuring the rest of the script out only to put it in geektool and be back to square one!

Could you also check the parameter for tab (\t) expansion. 3,4,8 anything else? It should be also consistent.

I'm sorry anathap I'm not sure how to check the tab (\t) expansion. What do you mean?