Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 17 Aug 2019, 21:00
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Two columns in leafpad or geany ??
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 5 of 6 [84 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6 Next
Author Message
Burunduk

Joined: 21 Aug 2011
Posts: 74

PostPosted: Wed 01 May 2019, 15:59    Post subject:  

Maybe it's OK to mention this old utility here.

Code:
pr -mt -S"|  " <(fold -s -w30 left.txt) <(fold -s -w30 right.txt) | expand >merged.txt
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Wed 01 May 2019, 16:12    Post subject:  

Burunduk wrote:
Maybe it's OK to mention this old utility here.
Code:
pr -mt -S"|  " <(fold -s -w30 left.txt) <(fold -s -w30 right.txt) | expand >merged.txt

That is really clever. Thanks!

The only problem is that i cannot seem to get text editors to handle Landscape mode. The lines wrap too early. I really need to be able to use Landscape.

EDIT: Also this method has a similar issue to musher0's earlier suggestion - it means that when i am re-editing the document i must pay very careful attention to what is happening with "insert" and movement / overwriting of the pipe characters.

Nonetheless - it seems these methods could be useful if I am maintaining WorkToDO and PersonalToDo as separate text files ready for inclusion into the merged output document..

thanks!
merged_text.jpg
 Description   
 Filesize   25.11 KB
 Viewed   309 Time(s)

merged_text.jpg

Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Thu 02 May 2019, 14:59    Post subject:  

Burunduk wrote:
Maybe it's OK to mention this old utility here.

Code:
pr -mt -S"|  " <(fold -s -w30 left.txt) <(fold -s -w30 right.txt) | expand >merged.txt
Hi Burunduk - do you have any idea why the pipe characters are "stuck" in column 34? I can see how the "w30" parameter determines the wrapping of the text contents, but i see no way to move the pipe characters to make a wider column in the merged output.
cheers!

(ps: maybe this is some sort of fixed kernel parameter related to console functions?)
- seems like page_width maxes out at 72 characters. I am struggling to understand why the pr output seems limited to 72 characters when leafpad can be forced to print landscape up to around 130 or 140 characters. Confusing Confused

Last edited by greengeek on Thu 02 May 2019, 15:30; edited 1 time in total
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Thu 02 May 2019, 15:01    Post subject:  

Just for future reference i will list here the syntax i found that lets me print the leafpad output as Landscape orientation (direct to whatever is set up as the default printer):
Code:
lp -olandscape -ofp12 -ovsi5.45 -otl66 -ohsi9.5 myfile.txt

It prints with narrow margins which suits my needs perfectly. Apparently the number of characters accommodated across the page is determined by the choice of character set (which is one of those funny parameter strings in the code above...)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14264
Location: Gatineau (Qc), Canada

PostPosted: Thu 02 May 2019, 15:18    Post subject:  

g\g?

What's your source for this?

Also, would you care to provide some details about what the parms do?

TIA.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Thu 02 May 2019, 15:40    Post subject:  

musher0 wrote:
g\g?

What's your source for this?

Also, would you care to provide some details about what the parms do?

TIA.
Source is here:
https://www.unix.com/unix-for-dummies-questions-and-answers/6668-how-print-text-file-landscape.html

As to what the parameters do - i am still very much in the dark. All i know is that syntax allowed me to print a leafpad file in landscape mode and it came out on my default printer - a Brother MFC7820 (despite the fact that the originator of the syntax was using an HP printer).

In that thread the respondent does make some comments about what the parameters are - but seems printer specific and sounds very techo.

I reckon if i decide to use separate Work/Personal ToDo lists they can be combined into two columns on a landscape page then the output printed. I feel it is getting closer...

EDIT : I feel that the contents of a text file are more or less "width agnostic" whereas a text file displayed is usually constrained by some sort of kernel console limitation of 72 characters wide. And i feel that a text file printed is of variable width depending on what utility formats it for printing. (This may sound like nonsense but it represents 100% accurately my current state of confusion) Confused
Back to top
View user's profile Send private message 
Burunduk

Joined: 21 Aug 2011
Posts: 74

PostPosted: Fri 03 May 2019, 12:57    Post subject:  

greengeek wrote:
- seems like page_width maxes out at 72 characters. I am struggling to understand why the pr output seems limited to 72 characters when leafpad can be forced to print landscape up to around 130 or 140 characters.


This is the default width.

Code:
pr -mt -o2 -S"*  " -W130 <(fold -s -w60 left.txt) <(fold -s -w60 right.txt) | expand >merged.txt


where -o2 indentation (witn 2 spaces)
-W130 page width (without the indent)

More information about pr
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Sat 04 May 2019, 12:59    Post subject:  

Burunduk wrote:
Code:
pr -mt -o2 -S"*  " -W130 <(fold -s -w60 left.txt) <(fold -s -w60 right.txt) | expand >merged.txt
Wow ! - thank you. That is very powerful and opens up some great possibilities for me.

The man page for "pr" says in a couple of places that the output page width is divided such that columns have the same width. Did I understand that correctly? Is that a global default with any pr syntax - so there is no option to have columns of different widths?

cheers!

EDIT : I changed the separator from * back to pipe |
merged_text_leafpad.jpg
 Description   
 Filesize   70.11 KB
 Viewed   215 Time(s)

merged_text_leafpad.jpg

Back to top
View user's profile Send private message 
Burunduk

Joined: 21 Aug 2011
Posts: 74

PostPosted: Sun 05 May 2019, 16:33    Post subject:  

greengeek wrote:
so there is no option to have columns of different widths?


It is not difficult to work this limitation around. When the width of the first column is decreased, there is a gap between the right margin and the separator but we can use cut to exclude it from the output.

Code:
pr -mt -S"*  " -W130 -o2 <(fold -s -w30 left.txt) <(fold -s -w60 right.txt) | expand | cut -c-33,64- >merged.txt


Ah, and I've found this elegant solution here

Code:
paste one.txt two.txt | expand --tabs=50


After some tweaking it looks considerably less elegant:

Code:
paste <(fold -s -w30 left.txt) <(fold -s -w60 right.txt) | sed 's/\t/&|  /' | expand -t33 >merged.txt


There should be no tabs in the input files.

But if your texts may contain non-ASCII characters, it's probably better to use a text processor.
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Tue 07 May 2019, 14:14    Post subject:  

Burunduk wrote:
After some tweaking it looks considerably less elegant:

Code:
paste <(fold -s -w30 left.txt) <(fold -s -w60 right.txt) | sed 's/\t/&|  /' | expand -t33 >merged.txt

Many thanks! This is getting very close to what I was looking for. The syntax works well in a terminal and works well in a bash script - but won't run for me in a shell script which means I can't seem to build it into a gtk gui.

I guess this means that the syntax contains a "bashism" or else I am failing to escape some variable properly. I have tried various quotes, backslashes, parentheses etc but just not hitting on the sweet spot.

Does anyone know how this can be changed to run in a shell script? What am I missing?

Code:
# ./shellmerge
./shellmerge: line 3: syntax error near unexpected token `('
./shellmerge: line 3: `paste <(fold -s -w30 left.txt) <(fold -s -w60 right.txt) | sed 's/\t/&|  /' | expand -t33 >merged.txt'
#

(I am using a Slacko 5.6 derivative)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1875
Location: Japan

PostPosted: Tue 07 May 2019, 20:02    Post subject:  

greengeek wrote:
works well in a bash script - but won't run for me in a shell script which means I can't seem to build it into a gtk gui.

??? A bash script is a shell script and I see no reason why it can't be used in a gtk gui.

The <(...) construct requires bash, so you have to make sure that your gui uses bash and not sh or anything else. Or use tmp files instead.
Back to top
View user's profile Send private message 
Burunduk

Joined: 21 Aug 2011
Posts: 74

PostPosted: Wed 08 May 2019, 15:18    Post subject:  

In other words, is there any good reason why you can't start your script with #!/bin/bash instead of #!/bin/sh?

The script below doesn't use process substitution. It also doesn't work very well. Perhaps I need to actually read that sed script inside.

Code:
#!/bin/sh

# halfedit -- version 0.1

# Edit each column of a two column text file separately.

# This script is a draft.


editor="geany -i"

col1=30
col2=60
sep="|  "

seppos=$((col1 + 2))

# fmt.sed http://sed.sourceforge.net/grabbag/scripts/fmt.sed

fmtsed1=':a
/^.\{'$col1'\}/!{
   $q
   N
   s/ *\n */ /
   ba
}
s/^.\{'$col1'\}/&\
/
s/^\(.*\) \(.*\)\n/\1\
\2/
P
s/^.*\n//
ba'

fmtsed2=':a
/^.\{'$col2'\}/!{
   $q
   N
   s/ *\n */ /
   ba
}
s/^.\{'$col2'\}/&\
/
s/^\(.*\) \(.*\)\n/\1\
\2/
P
s/^.*\n//
ba'


if [ ! -f "$1" ]; then
    echo "usage: this_script file.txt"
    exit 1
fi

filename="${1##*/}"
filename="${filename%%.*}"

# split the file in two

sed -r 's/(.{'$seppos'}).*/\1/' "$1" >"$filename"-left.txt
sed -r 's/.{'$seppos'}.{'${#sep}'}(.*)/\1/' "$1" >"$filename"-right.txt

# start the text editor

echo "Opening files for editing."
echo "Close the editor to continue."

$editor "$filename"-left.txt "$filename"-right.txt

# merge the edited files

sed -i "$fmtsed1" "$filename"-left.txt
sed -i "$fmtsed2" "$filename"-right.txt
mv "$1" "$1".bak
paste "$filename"-left.txt "$filename"-right.txt | sed "s/\\t/&$sep/" | expand -t$seppos >"$1"
rm -v "$filename"-left.txt "$filename"-right.txt

echo done

Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Wed 08 May 2019, 15:53    Post subject:  

MochiMoppel wrote:
??? A bash script is a shell script and I see no reason why it can't be used in a gtk gui.

Burunduk wrote:
In other words, is there any good reason why you can't start your script with #!/bin/bash instead of #!/bin/sh?


I did originally try substituting /bin/bash at the beginning of my gtk gui but it did not work so I assumed that the gui must remain in a /bin/sh form.

However, after your comments I am left with the inescapable conclusion that the problem is how I used variables within my gtk gui. I am trying to bring a variable ("$LEFTCOLUMNTEXTFILE") from the user gui into the "fold" portion of the bash script merge syntax and I obviously did it wrongly (many times and in many different ways...!)

I will change the gui to /bin/bash and will also focus on getting that fold syntax right. I had tried using /tmp files but that did not work so i must have stuffed that up too.... Confused

Back to the drawing board for a while...

Just for the record here is where I got to with my gui iterations before my brain melted:
Code:
#!/bin/bash

#greengeek 2019Apr30 GTK gui to assist with forming text version of ToDo list
#Merge syntax provided by Burunduk

export TEXTDOMAIN=ToDo2ColTextLister
export OUTPUT_CHARSET=UTF-8

DEFAULTBKUPDIR=/root
DEFAULTOUTNAME=/root/ToDo.txt

TMP="/tmp"

BUILD2COLUMNSOUT() {
   
STARTTIME=$(echo `date +%Y-%m-%d_%H%M%S`)
#gxmessage "start time = $STARTTIME"

COLUMN1=`cat "$LEFTCOLUMNTEXTFILE"`
COLUMN2=`cat "$RIGHTCOLUMNTEXTFILE"`

#Describe source file:
gxmessage "The text output file will be called '$OUTFILENAME-$STARTTIME'"

echo $LEFTCOLUMNTEXTFILE
echo $RIGHTCOLUMNTEXTFILE

#Script to build 2 column text output file
#paste "$LEFTCOLUMNTEXTFILE" "$RIGHTCOLUMNTEXTFILE" | expand --tabs=50 > "$OUTFILENAME-$STARTTIME"
paste <(fold -s -w30 "$LEFTCOLUMNTEXTFILE") <(fold -s -w60 "$RIGHTCOLUMNTEXTFILE") | sed 's/\t/&|  /' | expand -t33 > "$OUTFILENAME-$STARTTIME"
}
export -f BUILD2COLUMNSOUT

HELP () {
  defaultbrowser http://www.murga-linux.com/puppy/viewtopic.php?p=1027150#1027150
}
export -f HELP

# -------- End of Functions -----------

export PROG="
<window title=\"ToDo_2COLTEXT_gui_gg_0.1\">
<vbox>
  <frame $(gettext 'Select text file to load to left hand column')>
    <hbox>
      <entry accept=\"columnleft\">
      <variable>LEFTCOLUMNTEXTFILE</variable>
      </entry>
      <button>
        <input file stock=\"gtk-open\"></input>
        <action type=\"fileselect\">LEFTCOLUMNTEXTFILE</action>
      </button>
      <button>
          <input file stock=\"gtk-clear\"></input>
          <action>Clear:LEFTCOLUMNTEXTFILE</action>
      </button>
    </hbox>
  </frame>
    <frame $(gettext 'Select text file to load to right hand column')>
    <hbox>
      <entry accept=\"columnright\">
      <variable>RIGHTCOLUMNTEXTFILE</variable>
      </entry>
      <button>
        <input file stock=\"gtk-open\"></input>
        <action type=\"fileselect\">RIGHTCOLUMNTEXTFILE</action>
      </button>
      <button>
          <input file stock=\"gtk-clear\"></input>
          <action>Clear:RIGHTCOLUMNTEXTFILE</action>
      </button>
    </hbox>
  </frame>
  <frame $(gettext 'Save the 2column text output as this filename:
(Timestamp will be appended automatically)')>
    <hbox>
      <entry accept=\"outfilename\">
      <variable>OUTFILENAME</variable>
      <default>\"$DEFAULTOUTNAME\"</default>
      </entry>
      <button>
        <input file stock=\"gtk-open\"></input>
        <action type=\"fileselect\">OUTFILENAME</action>
      </button>
            <button>
          <input file stock=\"gtk-clear\"></input>
          <action>Clear:OUTFILENAME</action>
      </button>
    </hbox>
  </frame>
  <hbox>
    <button>
       <label>$(gettext 'Create 2column ToDo list')</label>
       <action>BUILD2COLUMNSOUT</action>
    </button>
  </hbox>
    <hbox>
    <text><label>\"   \"</label></text>
  </hbox>
    <hbox>
    <button>
     <label>$(gettext 'Help')</label>
     <action>HELP &</action>
    </button>
    <text><label>\"   \"</label></text>
    <button><label>$(gettext 'Quit')</label></button>
  </hbox>
</vbox>
</window>
"

gtkdialog3 -c -p PROG
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1875
Location: Japan

PostPosted: Wed 08 May 2019, 19:51    Post subject:  

<action>bash -c BUILD2COLUMNSOUT</action>
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5617
Location: Republic of Novo Zelande

PostPosted: Thu 09 May 2019, 14:45    Post subject:  

MochiMoppel wrote:
<action>bash -c BUILD2COLUMNSOUT</action>
Thank you very much! There is no way in 10million iterations i would have stumbled across that answer Smile

Attached below is version 0.2 of the two column text-output gui which produces columns of unequal width (as requested).

This is very close to what I was hoping for and I am getting quite excited. Razz

Line 8 in the output has minor misalignment but i cannot see what is unusual about that line in the source "personal" file. (I am putting the personal todo in the skinny column on the left and the work todo where there is more space on the right)
(EDIT : Seems to be the apostrophe in "don't" that is upsetting the alignment. Maybe different encoding or something. That text was imported from an email)

I have attached a sample persToDo and workToDo.

Remove fake .gz suffixes

EDIT :New version of this gui here
output.jpg
 Description   Line 8 funny but otherwise good progress
 Filesize   45.04 KB
 Viewed   63 Time(s)

output.jpg

ToDo_2colTEXT_gui_gg-0.2.gz
Description  Remove fake .gz suffix then make executable.
gz

 Download 
Filename  ToDo_2colTEXT_gui_gg-0.2.gz 
Filesize  2.82 KB 
Downloaded  32 Time(s) 
ToDoPers_Sample.txt.gz
Description  Remove fake .gz suffix
gz

 Download 
Filename  ToDoPers_Sample.txt.gz 
Filesize  325 Bytes 
Downloaded  34 Time(s) 
ToDoWork_Sample.txt.gz
Description  Remove fake .gz suffix
gz

 Download 
Filename  ToDoWork_Sample.txt.gz 
Filesize  383 Bytes 
Downloaded  32 Time(s) 

Last edited by greengeek on Sat 11 May 2019, 14:18; edited 1 time in total
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 5 of 6 [84 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0963s ][ Queries: 12 (0.0203s) ][ GZIP on ]