Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A solution using 'perl'. I suppose first column is 8 characters width.</p> <p>Program:</p> <pre><code>use strict; use warnings; ## Hash with contents of each line. Example: ## $file{ 1 } = "... line 1 ..." ## $file{ 2 } = "... line 2 ..." ## ... my %file; ## Max. number of characters of each column. ## $col_length[0] will have the max. number of characters of all string of ## first column, and the same for the others. my @col_length; while ( &lt;&gt; ) { next if /^\s*$/; chomp; ## Save fixed columns in array. ## A8 -&gt; 8 characters of first columns. ## A11 -&gt; 11 characters of second column. ## ... my @line = unpack( "A8A11A7A7", $_ ); ## Remove leading and trailing spaces of each field. @line = map { s/^\s*//; s/\s*$//; $_ } @line; ## Save max. number of characters of each column. for ( 0 .. $#line ) { my $l = length $line[$_]; $col_length[$_] = $l &gt; ($col_length[$_] || 0) ? $l : $col_length[$_]; } ## Save each input line. push @{ $file{ $. } }, @line; } ## Print to output. for ( sort { $a &lt;=&gt; $b } keys %file ) { my $format = join "", (map { "%" . $_ . "s" } @col_length), "\n"; printf $format, @{$file{ $_ }}; } </code></pre> <p>Input file (infile):</p> <pre><code> USA France 212 13 Canada Spain 34 23 Me ico Italy 4 390 india Portugal 5900 32 Malaysia Holland 15 43 </code></pre> <p>Execution:</p> <pre><code>$ perl script.pl infile </code></pre> <p>Output:</p> <pre><code> USA France 212 13 Canada Spain 34 23 Me ico Italy 4390 indiaPortugal5900 32 Malaysia Holland 15 43 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload