[ALUG] Manipulating files from bash
mark at more-solutions.co.uk
Mon Sep 25 10:27:52 BST 2017
On 23 September 2017 at 12:28, Martijn Koster <mak-alug at greenhills.co.uk> wrote:
> Typically the way I deal with something like that is hook up simple grep/seds into a few lines,
> inspecting/massaging the data as we go. For example, to create your minimal format:
> [.. big snip of really useful detailed info ..]
Thanks for that, I was already leaning towards sed (because I use it a
lot but only in basic ways so it makes sense to expand my knowledge of
it) and that has helped a huge amount.
awk is something I used to use a lot (getting on for 20 years ago) but
I'd have to think very hard to remember much from back then now.
> # remove the last line first number, and add a semicolon at the end
> # btw, what's that semicolon? Isn't that meant to be a comma?
The semicolon came from Googling for sfdisk scripting examples.
Stupidly I started there rather than "man sfdisk" which actually
explains things pretty well, and from a quick read of that (a quick
read is all you need when playing around with partitions right?? :-))
whitespace, commas and semicolons are all equivalent separators.
Having read the docs I'll go for something much closer to the output
generated by "sfdisk -d", massively simplifying the process for sed.
However, the reason for asking was a more broad general query as to
the best way to do things that are more complex. Stream editing is
fine when what you want out is broadly similar to what you put in, but
what about when the structure changes completely and values from near
the end of the input need to end up near the start of the output, etc?
What would be the best (generic) way to parse the input, capture a few
fields, and then generate a new output?
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450
Registered in England (0456 0902) 21 Drakes Mews, Milton Keynes, MK8 0ER
More information about the main