For this general class of problems, there are three Unix/Linux tools that you need to be aware of.
(a)
sed ("stream editor") is a tool that can take an input stream (file...), apply a filter or change to it, and write it to an output stream. This tool is usually used with the "|" (pipe) operator in a command.
(b)
grep ("regular expressions") is a great tool for finding files and for extracting useful pieces from those files.
(c)
awk is a
very powerful tool for ripping a file apart, record-by-record and field-by-field, and doing very sophisticated things with them.
Obviously, above-and-beyond this, programming languages like
perl and
python feature
hundreds of pre-built packages of existing code for doing these things and more.
Important Tip... In the Unix/Linux world, there are
many ways to do just about anything, and most if not all of them
have already been done. Usually, when you think about "building" a solution, you just need to "find" one.
Quote:
Originally Posted by a wise and very lazy sage:
Dictum ne agas -- Do not do a thing already done.
|