# Uncomment a COBOL program!

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

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:

apple
banana
donuts

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
oranges?
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.

## Clarifications

• 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.

## Scoring

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.

• Line numbers are not comments. They are a column. Terminology please. – user207421 Aug 24 '17 at 5:47
• Your examples all have a space after the *. Is this a coincidence? – Neil Aug 24 '17 at 10:13
• @Neil Yes, it is. The eighth character can be anything. – LyricLy Aug 24 '17 at 10:17
• 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. – Thorbjørn Ravn Andersen Aug 24 '17 at 12:06
• Can there be a space in the first 6 characters? – user4768 Aug 24 '17 at 15:30

# Japt, 11 10 bytes

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

k_g6 x
®t7

Test it (-R flag for visualisation purposes only)

• Saved a byte thanks to ETH.

## Explanation

Implicit input of array U.

f_

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

g6

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

x

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

®t7

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

• think the first line can be k_g6 x – ETHproductions Aug 24 '17 at 21:09
• @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 :) – 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
{\if#1*\else\write1{#2}\fi\egroup
}\everypar{\bgroup\d\\\d\{\d\}\a}

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! ((##${1[7]}<42))&&<<<${1:7:$}

Checks the ascii value of the 7th character.

# J, 20 bytes

7&}."1(#~'*'~:6&{"1)

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); foreach(file(C)as$s)echo$s[6]^b^x?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

{{6>'*#},7f>}

Try it online!

Explanation:

{           }  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:]<"*")|.[7:]

Explanation

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:]'
24

Try it online

# Implicit, 22 bytes

('\6¯_0=*!{]\1%ß1}]^ö

No explanation, sorry. I forgot how this works.

# Pyth - 15

V.z*.DNU7n@N6\*

Explanation:

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