7

art_file (cat -A output):

 .::""-,                      .::""-.$
/::     \                    /::     \$
|::     |   _..--""""--.._   |::     |$
'\:.__ /  .'              '.  \:.__ /$
 ||____|.' _..---"````'---. '.||____|$
 ||:.  |_.'                `'.||:.  |$
 ||:.-'`       .-----.        ';:.  |$
 ||/         .'       '.        \.  |$
 ||         / '-.   '. \\       |.  |$
 ||:.     _| '   \_\_\\/(        \  |$
 ||:.\_.-' )     ||   m `\.--._.-""-;$
 ||:.(_ . '\ __'// m ^_/ /    '.   _.`.$
 ||:.  \__^/` _)```'-...'   _ .-'.'    '-.$
 ||:..-'__  .'        '. . '      '.      `'.$
 ||:(_.' .`'        _. ' '-.         '.   . ''-._$
 ||:. :   '.     .'          '.  . ' ' '.`       '._$
 ||:.  :    '. .'     .::""-: .''.        ' .   . ' ':::''-.$
 ||:. .'    ..' .    /::     \    '.        . '.    /::     \$
 ||:.'    .'      '. |::     |    _.:---""---.._'   |::     |$
 ||.      :          '\:.__ /   .'    -.  .-    '.   \:.__ /$
 ||:     : '.       . ||____|_.'    .--.  .--.    '._||____|$
 ||:'.___:   '.   .'  ||:.  |      (    \/    )      ||:.  |$
 ||:___| \     '. :   ||:.  |       '-.    .-'       ||:.  |$
 [[____]  '.     '.-._||:.  |      __  '..'  __      ||:.  |$
            '.    :   ||:.  |     (__\ (\/) /__)     ||:.  |$
              '.  :   ||:.  |        `  \/  `        ||:.  |$
                '-:   ||:.  |           ()           ||:.  |$
                   '._||:.  |________________________||:.  |$
                      ||:___|'-.-'-.-'-.-'-.-'-.-'-.-||:___|$
                      [[____]                        [[____]$

caption_file (cat -A output):

$
$
  _________                     .__          $
 /   _____/____    _____ ______ |  |   ____  $
 \_____  \\__  \  /     \\____ \|  | _/ __ \ $
 /        \/ __ \|  Y Y  \  |_> >  |_\  ___/ $
/_______  (____  /__|_|  /   __/|____/\___  >$
        \/     \/      \/|__|             \/ $
___________              __                  $
\__    ___/___ ___  ____/  |_                $
  |    |_/ __ \\  \/  /\   __\               $
  |    |\  ___/ >    <  |  |                 $
  |____| \___  >__/\_ \ |__|                 $
             \/      \/                      $
$
$

I am trying to merge art_file with caption_file side by side. So far I have tried two methods:

  1. using pr -Jmt art_file caption_file

     .::""-,                      .::""-.
    /::     \                    /::     \
    |::     |   _..--""""--.._   |::     |        _________                        .__
    '\:.__ /  .'              '.  \:.__ /        /   _____/____    _____ ______ |  |     ____
     ||____|.' _..---"````'---. '.||____|        \_____  \\__    \  /     \\____ \|  | _/ __ \
     ||:.  |_.'                `'.||:.  |        /          \/ __ \|  Y Y  \  |_> >  |_\  ___/
     ||:.-'`       .-----.        ';:.  |       /_______  (____  /__|_|  /   __/|____/\___  >
     ||/         .'       '.        \.  |                 \/     \/      \/|__|             \/
     ||         / '-.   '. \\       |.  |       ___________                __
     ||:.     _| '   \_\_\\/(        \  |       \__      ___/___ ___  ____/  |_
     ||:.\_.-' )     ||   m `\.--._.-""-;         |      |_/ __ \\  \/  /\   __\
     ||:.(_ . '\ __'// m ^_/ /    '.   _.`.       |        |\  ___/ >    <  |  |
     ||:.  \__^/` _)```'-...'   _ .-'.'    '-.           |____| \___  >__/\_ \ |__|
     ||:..-'__  .'        '. . '      '.      `'.                      \/      \/
     ||:(_.' .`'        _. ' '-.         '.   . ''-._
     ||:. :   '.     .'          '.  . ' ' '.`       '._
     ||:.  :    '. .'     .::""-: .''.        ' .   . ' ':::''-.
     ||:. .'    ..' .    /::     \    '.        . '.    /::     \
     ||:.'    .'      '. |::     |    _.:---""---.._'   |::     |
     ||.      :          '\:.__ /   .'    -.  .-    '.   \:.__ /
     ||:     : '.       . ||____|_.'    .--.  .--.    '._||____|
     ||:'.___:   '.   .'  ||:.  |      (    \/    )      ||:.  |
     ||:___| \     '. :   ||:.  |       '-.    .-'       ||:.  |
     [[____]  '.     '.-._||:.  |      __  '..'  __      ||:.  |
                '.    :   ||:.  |     (__\ (\/) /__)     ||:.  |
                  '.  :   ||:.  |        `  \/  `        ||:.  |
                    '-:   ||:.  |           ()           ||:.  |
                       '._||:.  |________________________||:.  |
                          ||:___|'-.-'-.-'-.-'-.-'-.-'-.-||:___|
                          [[____]                        [[____]
    
  2. paste art_file caption_file

 .::""-,                      .::""-.
/::     \                    /::     \
|::     |   _..--""""--.._   |::     |        _________                     .__
'\:.__ /  .'              '.  \:.__ /        /   _____/____    _____ ______ |  |   ____
 ||____|.' _..---"````'---. '.||____|        \_____  \\__  \  /     \\____ \|  | _/ __ \
 ||:.  |_.'                `'.||:.  |        /        \/ __ \|  Y Y  \  |_> >  |_\  ___/
 ||:.-'`       .-----.        ';:.  |       /_______  (____  /__|_|  /   __/|____/\___  >
 ||/         .'       '.        \.  |               \/     \/      \/|__|             \/
 ||         / '-.   '. \\       |.  |       ___________              __
 ||:.     _| '   \_\_\\/(        \  |       \__    ___/___ ___  ____/  |_
 ||:.\_.-' )     ||   m `\.--._.-""-;         |    |_/ __ \\  \/  /\   __\
 ||:.(_ . '\ __'// m ^_/ /    '.   _.`.       |    |\  ___/ >    <  |  |
 ||:.  \__^/` _)```'-...'   _ .-'.'    '-.    |____| \___  >__/\_ \ |__|
 ||:..-'__  .'        '. . '      '.      `'.                    \/      \/
 ||:(_.' .`'        _. ' '-.         '.   . ''-._
 ||:. :   '.     .'          '.  . ' ' '.`       '._
 ||:.  :    '. .'     .::""-: .''.        ' .   . ' ':::''-.
 ||:. .'    ..' .    /::     \    '.        . '.    /::     \
 ||:.'    .'      '. |::     |    _.:---""---.._'   |::     |
 ||.      :          '\:.__ /   .'    -.  .-    '.   \:.__ /
 ||:     : '.       . ||____|_.'    .--.  .--.    '._||____|
 ||:'.___:   '.   .'  ||:.  |      (    \/    )      ||:.  |
 ||:___| \     '. :   ||:.  |       '-.    .-'       ||:.  |
 [[____]  '.     '.-._||:.  |      __  '..'  __      ||:.  |
            '.    :   ||:.  |     (__\ (\/) /__)     ||:.  |
              '.  :   ||:.  |        `  \/  `        ||:.  |
                '-:   ||:.  |           ()           ||:.  |
                   '._||:.  |________________________||:.  |
                      ||:___|'-.-'-.-'-.-'-.-'-.-'-.-||:___|
                      [[____]                        [[____]

Both of them mess up the alignment of the second file, with paste generating a somewhat better output. So my questions are:

  1. Using either paste or pr can I generate desired output? Some option(s) I am overlooking, perhaps?
  2. If neither of them are the correct tools for the job, other than writing a new program, what pre-existing solution can I use?

1 Answer 1

2

The trouble is each line has a different length. The easiest solution is to give a large enough width to pr:

pr -mtw 150 art_file caption_file

If you want the caption text to get closer, I suggest

awk '
  l<length && NR<=n{l=length}
  NR!=FNR{
    printf "%-"l"s", $0
    getline line < "caption"
    print line
  }
' n="$(wc -l < caption)" art art
  • n is the number of lines of the caption file.
  • l is the length of the longest line between the first n lines of the art file.
  • printf right-pads the art file with spaces so that it all its lines have l length.
  • getline then gets a line from the caption file and prints it next to the just printed art line.

Note that you can add or subtract to the value of l in printf to ad-hoc adjust the spacing.

 .::""-,                      .::""-.
/::     \                    /::     \
|::     |   _..--""""--.._   |::     |                _________                     .__
'\:.__ /  .'              '.  \:.__ /                /   _____/____    _____ ______ |  |   ____
 ||____|.' _..---"````'---. '.||____|                \_____  \\__  \  /     \\____ \|  | _/ __ \
 ||:.  |_.'                `'.||:.  |                /        \/ __ \|  Y Y  \  |_> >  |_\  ___/
 ||:.-'`       .-----.        ';:.  |               /_______  (____  /__|_|  /   __/|____/\___  >
 ||/         .'       '.        \.  |                       \/     \/      \/|__|             \/
 ||         / '-.   '. \\       |.  |               ___________              __
 ||:.     _| '   \_\_\\/(        \  |               \__    ___/___ ___  ____/  |_
 ||:.\_.-' )     ||   m `\.--._.-""-;                 |    |_/ __ \\  \/  /\   __\
 ||:.(_ . '\ __'// m ^_/ /    '.   _.`.               |    |\  ___/ >    <  |  |
 ||:.  \__^/` _)```'-...'   _ .-'.'    '-.            |____| \___  >__/\_ \ |__|
 ||:..-'__  .'        '. . '      '.      `'.                    \/      \/
 ||:(_.' .`'        _. ' '-.         '.   . ''-._
 ||:. :   '.     .'          '.  . ' ' '.`       '._
 ||:.  :    '. .'     .::""-: .''.        ' .   . ' ':::''-.
 ||:. .'    ..' .    /::     \    '.        . '.    /::     \
 ||:.'    .'      '. |::     |    _.:---""---.._'   |::     |
 ||.      :          '\:.__ /   .'    -.  .-    '.   \:.__ /
 ||:     : '.       . ||____|_.'    .--.  .--.    '._||____|
 ||:'.___:   '.   .'  ||:.  |      (    \/    )      ||:.  |
 ||:___| \     '. :   ||:.  |       '-.    .-'       ||:.  |
 [[____]  '.     '.-._||:.  |      __  '..'  __      ||:.  |
            '.    :   ||:.  |     (__\ (\/) /__)     ||:.  |
              '.  :   ||:.  |        `  \/  `        ||:.  |
                '-:   ||:.  |           ()           ||:.  |
                   '._||:.  |________________________||:.  |
                      ||:___|'-.-'-.-'-.-'-.-'-.-'-.-||:___|
                      [[____]                        [[____]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.