Code: Select all
pr -mt -S"| " <(fold -s -w30 left.txt) <(fold -s -w30 right.txt) | expand >merged.txt
Code: Select all
pr -mt -S"| " <(fold -s -w30 left.txt) <(fold -s -w30 right.txt) | expand >merged.txt
That is really clever. Thanks!Burunduk wrote:Maybe it's OK to mention this old utility here.Code: Select all
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.Burunduk wrote:Maybe it's OK to mention this old utility here.
Code: Select all
pr -mt -S"| " <(fold -s -w30 left.txt) <(fold -s -w30 right.txt) | expand >merged.txt
Code: Select all
lp -olandscape -ofp12 -ovsi5.45 -otl66 -ohsi9.5 myfile.txt
Source is here:musher0 wrote:g\g?
What's your source for this?
Also, would you care to provide some details about what the parms do?
TIA.
This is the default width.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.
Code: Select all
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.Burunduk wrote:Code: Select all
pr -mt -o2 -S"* " -W130 <(fold -s -w60 left.txt) <(fold -s -w60 right.txt) | expand >merged.txt
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.greengeek wrote:so there is no option to have columns of different widths?
Code: Select all
pr -mt -S"* " -W130 -o2 <(fold -s -w30 left.txt) <(fold -s -w60 right.txt) | expand | cut -c-33,64- >merged.txt
Code: Select all
paste one.txt two.txt | expand --tabs=50
Code: Select all
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.Burunduk wrote:After some tweaking it looks considerably less elegant:
Code: Select all
paste <(fold -s -w30 left.txt) <(fold -s -w60 right.txt) | sed 's/\t/&| /' | expand -t33 >merged.txt
Code: Select all
# ./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'
#
??? A bash script is a shell script and I see no reason why it can't be used in a gtk gui.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.
Code: Select all
#!/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
MochiMoppel wrote:??? A bash script is a shell script and I see no reason why it can't be used in a gtk gui.
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.Burunduk wrote:In other words, is there any good reason why you can't start your script with #!/bin/bash instead of #!/bin/sh?
Code: Select all
#!/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
Thank you very much! There is no way in 10million iterations i would have stumbled across that answerMochiMoppel wrote:<action>bash -c BUILD2COLUMNSOUT</action>
Not maybe. If you *would* use MMview (SCNR ) you could see that this file is UTF-8 encoded while the file ToDoWork_Sample.txt is US_ASCII encoded. And if you would use the newest version you could even spot the problem, using 'Hexview' (not ''Hexdump'). It's indeed the apostrophe, which in this case is not the usual ASCII apostrophe but Unicode U+2019 (RIGHT SINGLE QUOTATION MARK). This character takes up 3 bytes instead of the usual 1 byte. The expand command calculates the tab stop based on bytes, not characters, so it sees 25 bytes in the text when you see only 23 characters, adds 8 spaces and voilà, 33 bytes.greengeek wrote:Line 8 in the output has minor misalignment but i cannot see what is unusual about that line in the source "personal" file. ...
(EDIT : Seems to be the apostrophe in "don't" that is upsetting the alignment. Maybe different encoding or something.
Awesome analysis, thank you.MochiMoppel wrote:Well, let's call this a bug. This is not how the expand command should work. Buggy in version 8.19 and still buggy in 8.24.
The solution: use busybox expand instead. It's not the first time that busybox is better maintained than the GNU utilities.
Code: Select all
busybox expand