There are four great
tools in the Unix/Linux world that are terrific for handling problems like these. I'll introduce them individually....
("stream editor") is very useful when you have a single file that you want to do something to, to produce another single file as output. (In Linux/Unix-land, this idea is often applied as a "filter" when "piping" things ... but that's another story...)
is a great tool for finding which files contain a particular string. It grows on you... For example, when I needed to find all of the files in a great-big directory (which contains over 3,500 files in various subdirectories) which contained the word "arp" as a whole-word (that is to say, surrounded on both sides by a character that is not a letter), regardless of UPPer or LoWeR CAse, I "merely" typed: grep -rilw arp ~/projects/*
Nothin' to it...
is probably the tool that you want in this
case. The file that you need to process has certain definitely-identifiable characteristics, such as:
- There's one "record" per "line," and it seems that "fields" in each "record" are separated by "one or more spaces."
- "A line that begins with 'O' followed by one-or-more 'digits'" marks the beginning of "something I am interested in," and when I see such a record, "the second field" (filename) "is interesting."
- After I have seen a record like that, zero-or-more records contain useful text...
- "But when I see a record starting with 'X' followed by zero-or-more 'digits'" I want to...
Well, you get the idea. awk
is a tool that's designed
for things like that.
For the truly adventurous, the programming language perl
was actually designed
by a person who started his quest by "extending awk
" and ... well ... "one thing lead to another," as things in our peculiar industry so-often do.