Did you ever have to get an error message from the Virtual Console and had nothing but cat /dev/vcs# > filename
or fold -w 81 /dev/vcs# to use to get the text into something you could throw in a request for help?

The problem with using those methods is that they are grabbing the text directly from memory, which doesn't have real newline chars (0xa) in it. In the sreen capture I had done... the first 128 characters were all space chars (0x20). When I viewed it in Midnight Commander without wordwrap on... the whole fille was on 1 line. With wordwrap on... it was a mess.

When cat grabs the text from memory, since it is really just a fixed height & width of memory that represents your console screen... (mine was set at 128 Columns x 48 Lines) it can't guess where the end of each line is, though I wished for a "fixed line" length option... I didn't see any. So I set about finding some other solutions. (I knew I wasn't the first one who wanted to do this.)

Ok... Well I did find
fold -w 128 /dev/vcs1
and that works well enough in konsole to use my mouse and copy it and paste it in a kwrite editor window. But it's still a manual process.

Here is a script that will make 2 files.
/home/knoppix/fixScreenGrabs.bash and a
/home/knoppix/Desktop/fixScreenGrabs.desktop file to invoke it.

I used KDE kdialogs to pick files with etc... and it can be invoked with a file name parameter. This should be a screen grabbed with cat /dev/vcs# where # is the Virtual Console number you are grabbing text from.

fixScreenGrabs.bash will ask you for the Rows and Columns of your VC's. If you don't know you can examine your $LINES and $COLUMNS variables from a VC. Konsole is resizable so that will throw you off if you examine those variables from within it.

For me it was a challenge to find out ways to access a file with fixed record lengths without asking
The docs for gawk say the parameter to FIELDWIDTHS must be a double quoted list numbers which state the length of each field. That would have been " 128..." 48 times! So I found that if I export the $LREC variable... which I used seq to make during runtime... and store in $LREC that ENVIRON["LREC"] actually worked in gawk.

Initially I had the gawk program in a separate file but the 2 methods are not the same. I'll leave it there for now... maybe someone can answer some questions I had about it... but now it is all on one line.

The quote block below is a script that manufactures the 2 files. The white space is not preserved but otherwise a diff -w said it is the same as mine. It's late... so here.


# write /home/knoppix/fixScreenGrabs.bash
echo \#\!/bin/bash > /home/knoppix/fixScreenGrabs.bash
echo \# fold -w 128 /dev/vcs1 is a good start but it winds up with no newlines >> /home/knoppix/fixScreenGrabs.bash
echo >> /home/knoppix/fixScreenGrabs.bash
echo \i\f \[ \! -z \"\$\1\" \] \&\& \[ -e \"\$\1\" \] \; \then >> /home/knoppix/fixScreenGrabs.bash
echo SCREENCAP=\$\1 >> /home/knoppix/fixScreenGrabs.bash
echo else >> /home/knoppix/fixScreenGrabs.bash
echo SCREENCAP=\`kdialog --getopenfilename .\` >> /home/knoppix/fixScreenGrabs.bash
echo \f\i >> /home/knoppix/fixScreenGrabs.bash
echo >> /home/knoppix/fixScreenGrabs.bash
echo \i\f \[ \! -w \$SCREENCAP \] \; \then >> /home/knoppix/fixScreenGrabs.bash
echo \echo \"You don\'t have write permissions \for that \file\" >> /home/knoppix/fixScreenGrabs.bash
echo \exit 1 >> /home/knoppix/fixScreenGrabs.bash
echo \f\i >> /home/knoppix/fixScreenGrabs.bash
echo >> /home/knoppix/fixScreenGrabs.bash
echo FSGLINES=\`kdialog --title \"Console Lines\" --inputbox \"How many rows does your console have?\" \"48\"\` >> /home/knoppix/fixScreenGrabs.bash
echo FSGCOLUMNS=\`kdialog --title \"Console Columns\" --inputbox \"How many characters wide is your console\" \"128\"\` >> /home/knoppix/fixScreenGrabs.bash
echo LREC=\$\( \for i \in \`\seq -s \" \" 1 \$FSGLINES\` \; \do \echo -n \$FSGCOLUMNS\" \" \; \done \) >> /home/knoppix/fixScreenGrabs.bash
echo export LREC >> /home/knoppix/fixScreenGrabs.bash
echo >> /home/knoppix/fixScreenGrabs.bash

echo AWKOUT=\`mktemp \$SCREENCAP.XXXXXX\` >> /home/knoppix/fixScreenGrabs.bash
echo awk \'BEGIN \{FIELDWIDTHS = ENVIRON\[\"LREC\"\] \}\{\for\(i = 1\; i\<=NF\; i++\) print \$i\}\'\ \$SCREENCAP\ \>\ \$AWKOUT >> /home/knoppix/fixScreenGrabs.bash

# echo \a\w\k -f /home/knoppix/fixScreenGrabs.awk \$SCREENCAP \> \$AWKOUT >> /home/knoppix/fixScreenGrabs.bash
echo >> /home/knoppix/fixScreenGrabs.bash
echo \kdialog --textbox \$AWKOUT 600 400 >> /home/knoppix/fixScreenGrabs.bash
echo \kdialog --title \"Confirm Save\" --yesno \"Do you want to keep that file?\" >> /home/knoppix/fixScreenGrabs.bash
echo >> /home/knoppix/fixScreenGrabs.bash
echo \i\f \[ \"\$\?\" -eq 1 \] \; \then >> /home/knoppix/fixScreenGrabs.bash
echo \r\m -f \$AWKOUT >> /home/knoppix/fixScreenGrabs.bash
echo \e\l\s\e >> /home/knoppix/fixScreenGrabs.bash
echo \c\p -f \$AWKOUT \$SCREENCAP >> /home/knoppix/fixScreenGrabs.bash
echo \r\m -f \$AWKOUT >> /home/knoppix/fixScreenGrabs.bash
echo \f\i >> /home/knoppix/fixScreenGrabs.bash
echo >> /home/knoppix/fixScreenGrabs.bash

# I had this working but there are problems with awk -f program
# cat /home/knoppix/fixScreenGrabs.awk
# echo \BEGIN \{ print ENVIRON\[\"\$LREC\"\] > /home/knoppix/fixScreenGrabs.awk
# echo " # Bash generated and stored for us." >> /home/knoppix/fixScreenGrabs.awk
# echo " # FIELDWIDTHS = \"128 128 128 128 128 128 80\"" >> /home/knoppix/fixScreenGrabs.awk
# echo " # Instead of 80 \"128 \"s we will use an environment var" >> /home/knoppix/fixScreenGrabs.awk
# echo >> /home/knoppix/fixScreenGrabs.awk
# echo FIELDWIDTHS = ENVIRON\[\"\$LREC\"\] >> /home/knoppix/fixScreenGrabs.awk
# echo >> /home/knoppix/fixScreenGrabs.awk
# echo \} >> /home/knoppix/fixScreenGrabs.awk
# echo >> /home/knoppix/fixScreenGrabs.awk
# echo \{ >> /home/knoppix/fixScreenGrabs.awk
# echo >> /home/knoppix/fixScreenGrabs.awk
# echo \for\(i = 1\; i\<=NF\; i\+\+\) >> /home/knoppix/fixScreenGrabs.awk
# echo \print \$\i >> /home/knoppix/fixScreenGrabs.awk
# echo >> /home/knoppix/fixScreenGrabs.awk
# echo \} >> /home/knoppix/fixScreenGrabs.awk

# write /home/knoppix/Desktop/fixScreenGrabs.desktop
echo \[Desktop Entry\] > /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Comment= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Comment\[en_US]\= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Encoding=UTF-8 >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Exec=/home/knoppix/fixScreenGrabs.bash >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo GenericName= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo GenericName\[en_US\]= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Icon=xfce4-settings >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo MimeType= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Name=fixScreenGrabs >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Name\[en_US\]=fixScreenGrabs >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Path=/home/knoppix/ >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo StartupNotify=true >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Terminal=false >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo TerminalOptions= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo Type=Application >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo X-DCOP-ServiceType= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo X-KDE-SubstituteUID=\false >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo X-KDE-Username= >> /home/knoppix/Desktop/fixScreenGrabs.desktop
echo >> /home/knoppix/Desktop/fixScreenGrabs.desktop

chmod +x /home/knoppix/fixScreenGrabs.bash

exit 0