COBOL is a very old language, at the time of writing it is 58 years old. It is so old, in fact, that it has a very interesting quirk: the first six characters of each line are comments.

Why is this, you ask? Well, those 6 characters were intended to be used as line numbers, back in the day where programs weren't completely digital and typed out on a computer.

In addition, the seventh character could only be part of a very small set (it is usually * to comment out the line or a space to separate the line number from the code)

But what if you're on a more digital system, and you just want the raw program?

The comment system

There are two types of comments in COBOL: line comments and the aforementioned "line number" comments.

Uncommenting line numbers is simple: just take the first seven (six plus a single space) characters off each line.

000000 apple
000001 banana
celery donuts

would become:


Line comments make it a bit more difficult. A line comment is started with an asterisk * placed in the seventh character position on the line, like so:

000323* this is a comment

This is not a line comment:

*00000 this isn't a comment

To uncomment a line comment, just remove the whole line.

An example commented "program":

000000 blah blah
000001* apples
000002 oranges?
000003* yeah, oranges.
000*04 love me some oranges

The uncommented version:

blah blah
love me some oranges

In other words, to uncomment a string, remove the first six characters of each line, then return all but the first character of every line that does not begin with a star.

The challenge

Create a program or function that takes a commented program and returns its uncommented variant.


  • Asterisks (*) will never be found anywhere outside the first seven characters on a line (we're not asking you to verify syntax)
  • Each line will always have at least 7 characters.
  • You may assume the seventh character is always an asterisk or a space.
  • Input or output may be a matrix or list.
  • Only printable ASCII characters (plus newline) must be handled.
  • You may output with a trailing newline. You may also assume that the input will have a trailing newline, if you so choose.


Since this is , the answer with the least bytes wins!

DISCLAIMER: I do not actually know COBOL and do not claim to. If any of the claims about COBOL I have made in this question are incorrect, I take no responsibility.

  • 23
    \$\begingroup\$ Line numbers are not comments. They are a column. Terminology please. \$\endgroup\$ – user207421 Aug 24 '17 at 5:47
  • 2
    \$\begingroup\$ Your examples all have a space after the *. Is this a coincidence? \$\endgroup\$ – Neil Aug 24 '17 at 10:13
  • 1
    \$\begingroup\$ @Neil Yes, it is. The eighth character can be anything. \$\endgroup\$ – LyricLy Aug 24 '17 at 10:17
  • 6
    \$\begingroup\$ Old does not automatically imply bad. I have worked in an Agile COBOL shop. They could do things on the AS/400 we could not do in Java. \$\endgroup\$ – Thorbjørn Ravn Andersen Aug 24 '17 at 12:06
  • 4
    \$\begingroup\$ Can there be a space in the first 6 characters? \$\endgroup\$ – user4768 Aug 24 '17 at 15:30

40 Answers 40


Japt, 11 10 bytes

Takes input as an array of strings and outputs an array of strings.

k_g6 x

Test it (-R flag for visualisation purposes only)

  • Saved a byte thanks to ETH.


Implicit input of array U.


Filter (f) by passing each element through a function.


Get the character at index (g) 6 (0-indexed).


Trim, giving either * (truthy) or an empty string (falsey).


Map (®) over the array and get the substring (t) of each element from the 7th character. Implicitly output the resulting array.

  • \$\begingroup\$ think the first line can be k_g6 x \$\endgroup\$ – ETHproductions Aug 24 '17 at 21:09
  • \$\begingroup\$ @ETHproductions: Today was not a good day's golfing for me - I was playing around with solutions using x, as seen in my alt. solution, and I still didn't twig that! Thanks once again :) \$\endgroup\$ – Shaggy Aug 24 '17 at 23:15

TeX - 139 bytes

\let~\def~\a#1#2#3#4#5#6{\b}~\d#1{\catcode`#1=12}\obeylines\d\ ~\b#1#2

Eats up the first six characters of each line, then checks if the next one is an asterisk or something else. Recurses over lines by eating up anything that tries to get typeset. The rest of my bytes are spent on changing category codes of syntax related characters so it's robust.


Javascript, 37 bytes

Regexp-based solution

s=>s.replace(/^.{6}( |(\*.+$\n?))/gm,'')

Zsh, 29 bytes

try it online!


Checks the ascii value of the 7th character.


J, 20 bytes


This assumes the input is a matrix of equal-length space-padded lines.


PHP, 50 bytes

foreach(file(C)as$s)$s[6]>" "||print substr($s,7);

same length:

foreach(file(C)as$s)$s[6]^a^q||print substr($s,7);
foreach(file(C)as$s)$s[6]^b^x&&print substr($s,7);

regex solution, 51 bytes:

<?=join(preg_filter("#^.{6} (.*)$#","$1",file(C)));

builtins only, 108 bytes:

<?=join(array_map(function($s){return substr($s,7);},array_filter(file(C),function($s){return$s[6]^b^x;})));

take code from a file named C. Run with -nr or try them online.


CJam, 13 bytes


Try it online!


{           }  e# Block. Input:                ["000000 blah blah" "000001* apples" "000002 oranges?" "000003* yeah, oranges."]
 {     },      e# Filter on the following:
  6>           e#   Remove first 6 characters: [" blah blah" "* apples" " oranges?" "*yeah, oranges"]
    '*#        e#   Find a '*':                [-1 0 -1 0]
               e# End filter:                  ["000000 blah blah" "000002 oranges?"]
         7f>   e# Remove first 7 characters:   ["blah blah" "oranges?"]

Jq 1.5, 24 bytes



  select(.[6:] < "*")          # discard if '*' in column 7
| .[7:]                        # keep remaining portion

Sample run with paste to show input vs output

$ paste input <(jq -MRr 'select(.[6:]<"*")|.[7:]' input)
000000 blah blah                blah blah            
000001* apples                  oranges?                    
000002 oranges?                 love me some oranges 
000003* yeah, oranges.          
000*04 love me some oranges

$ wc -c <<<'select(.[6:]<"*")|.[7:]'

Try it online


Implicit, 22 bytes


No explanation, sorry. I forgot how this works.


Pyth - 15



V.z              For each line N in input
     N             N
   .D U7           but with characters 0-6 removed
  *                times
          @N6       Item six of N
         n          Does not equal
             \*     "*"

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.