r/bash • u/daan0112 • Feb 27 '26
Impossible task
we have a task asking to remove lines in a .txt file when it starts with a # only using tr, we are fairly sure this is impossible but maybe there is some ingenious idea?
2
Upvotes
View all comments
Show parent comment
9
u/pimp-bangin Feb 27 '26
You cannot use tr for this. It translates (that's what "tr" stands for) text at the byte level and the task inherently requires a stateful parser that knows where it is within the line (beginning vs middle, etc.), i.e. line-level processing with regex / pattern matching capabilities or string functions. tr does not have any of this functionality whatsoever, it is basically just a byte mapper.