[ALUG] Manipulating files from bash

steve-ALUG at hst.me.uk steve-ALUG at hst.me.uk
Fri Sep 22 17:44:13 BST 2017

On 22/09/17 17:05, Mark Rogers wrote:
> There are lots of ways to process text files (eg sed, awk, etc); I'm
> after suggestions on the best/easiest way to achieve something fairly
> trivial to describe.
> Below is example output from sfdisk -d:
>     label: dos
>     label-id: 0xe3f4f21a
>     device: /dev/sdd
>     unit: sectors
>     /dev/sdd1 : start=        8192, size=       85622, type=c
>     /dev/sdd2 : start=       94208, size=     5521408, type=83
>     /dev/sdd3 : start=     5615616, size=    25499648, type=83
> I want to convert this into a new script to go back into sfdisk but
> with some changes; I want the start values skipped (so sfdisk will put
> partition boundaries wherever it thinks is best), I want the last
> sector not have a size (ie "rest of disk"), and I don't really need
> any of the settings at the top.
> In fact, a suitable (minimal) script to go into sfdisk would be simply:
>    ,85622,c
>    ,5521408
>    ,;
> I don't really mind at this point whether I end up with something more
> like the first format or minified like the latter. In fact to be
> honest I'm more interested just in learning the best ways to play with
> text files like this.
sed will probably do what you want.  It can edit files in place or write 
output to a spearate file, search and replace, and has wildcards.  
There's lots to it though, so I suggest a trip to the manual


More information about the main mailing list