Remove command line options (mode-flags w/ options) from single line string in file

File mkisofs has the following one line string:

xorriso -as mkisofs -r -checksum_algorithm_iso sha256,sha512 -V 'Debian 12.0.0 amd64 n' -o /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/debian-12.0.0-amd64-NETINST-1.iso -checksum-list /srv/cdbuilder.debian.org/src/deb-cd/tmp/2bookwormamd64/bookworm/checksum-check -jigdo-checksum-algorithm md5 -jigdo-force-checksum /pool/ -jigdo-min-file-size 1024 -jigdo-exclude 'README*' -jigdo-exclude /doc/ -jigdo-exclude /md5sum.txt -jigdo-exclude /.disk/ -jigdo-exclude /pics/ -jigdo-exclude 'Release*' -jigdo-exclude 'Packages*' -jigdo-exclude 'Sources*' -jigdo-jigdo /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/debian-12.0.0-amd64-NETINST-1.jigdo -jigdo-template /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/debian-12.0.0-amd64-NETINST-1.template -jigdo-map Debian=/srv/cdbuilder.debian.org/src/ftp/debian/ -jigdo-exclude boot1 -J -joliet-long -cache-inodes -isohybrid-mbr syslinux/usr/lib/ISOLINUX/isohdpfx.bin -b isolinux/isolinux.bin -c isolinux/boot.cat -boot-load-size 4 -boot-info-table -no-emul-boot -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus boot1 CD1

I need to remove every mode-flag with its options that start with "-jidgo". This is for part of the script I’m writing. Native or sed options preferred, but willing to expand resources to get the job done.

I was able to remove them after putting each mode-flag on a separate line, and then running:

sed -i 's/-jigdo-[^-]*//' mkisofs
sed -i 's/-jigdo[^-]*//' mkisofs

This doesn’t work if left as one string. I also had to create two commands because it would only do a partial remove on "jigdo-exclude".

For a better view, this is what it looks like after spacing each line:

xorriso
-as mkisofs
-r
-checksum_algorithm_iso sha256,sha512
-V 'Debian 12.0.0 amd64 n'
-o /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/debian-12.0.0-amd64-NETINST-1.iso
-checksum-list /srv/cdbuilder.debian.org/src/deb-cd/tmp/2bookwormamd64/bookworm/checksum-check
-jigdo-checksum-algorithm md5
-jigdo-force-checksum /pool/
-jigdo-min-file-size 1024
-jigdo-exclude 'README*'
-jigdo-exclude /doc/
-jigdo-exclude /md5sum.txt
-jigdo-exclude /.disk/
-jigdo-exclude /pics/
-jigdo-exclude 'Release*'
-jigdo-exclude 'Packages*'
-jigdo-exclude 'Sources*'
-jigdo-jigdo /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/debian-12.0.0-amd64-NETINST-1.jigdo
-jigdo-template /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/debian-12.0.0-amd64-NETINST-1.template
-jigdo-map Debian=/srv/cdbuilder.debian.org/src/ftp/debian/
-jigdo-exclude boot1
-J
-joliet-long
-cache-inodes
-isohybrid-mbr syslinux/usr/lib/ISOLINUX/isohdpfx.bin
-b isolinux/isolinux.bin
-c isolinux/boot.cat
-boot-load-size 4
-boot-info-table
-no-emul-boot
-eltorito-alt-boot
-e boot/grub/efi.img
-no-emul-boot
-isohybrid-gpt-basdat
-isohybrid-apm-hfsplus boot1 CD1

This is what it should look like when modified as a one line string:

xorriso -as mkisofs -r -checksum_algorithm_iso sha256,sha512 -V 'Debian 12.0.0 amd64 n' -o /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/debian-12.0.0-amd64-NETINST-1.iso -checksum-list /srv/cdbuilder.debian.org/src/deb-cd/tmp/2bookwormamd64/bookworm/checksum-check -J -joliet-long -cache-inodes -isohybrid-mbr syslinux/usr/lib/ISOLINUX/isohdpfx.bin -b isolinux/isolinux.bin -c isolinux/boot.cat -boot-load-size 4 -boot-info-table -no-emul-boot -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus boot1 CD1

Asked By: Jeremy Burcham

||

Unless I’m overlooking something, this seems to work with the little bit of testing I’ve done:

sed -i -r 's/-jigdo[^ ]+ [^ ]+ //g' filename
Answered By: pell

I asked Bing AI my question. Here is what worked…

You can use sed to remove the mode-flags and their options that start with -jigdo. Here’s an example command that should work:

sed 's/-jigdo[^ ]* [^ ]*//g' input.txt > output.txt
Copy
This command uses a regular expression to match any text that starts with -jigdo, followed by any number of characters that are not a space, followed by a space, and then any number of characters that are not a space. This will match the mode-flag and its option. The g at the end of the command tells sed to perform this replacement globally, i.e., for all occurrences in the input line.

You can replace input.txt with the name of the file containing the original line, and output.txt with the name of the file where you want to save the modified line. If you want to perform this operation in-place, i.e., modify the original file directly, you can use the -i option:

sed -i 's/-jigdo[^ ]* [^ ]*//g' input.txt
Copy
I hope this helps! Let me know if you have any questions or if there’s anything else I can do for you.

1
of
30

Like

Dislike

Copy

Export
How do I then clear any extra spaces between the mode-flags?
You can use another sed command to remove any extra spaces between the mode-flags. Here’s an example command that should work:

sed 's/  */ /g' input.txt > output.txt
Copy
This command uses a regular expression to match any sequence of one or more spaces and replaces it with a single space. The g at the end of the command tells sed to perform this replacement globally, i.e., for all occurrences in the input line.

You can replace input.txt with the name of the file containing the line with extra spaces, and output.txt with the name of the file where you want to save the modified line. If you want to perform this operation in-place, i.e., modify the original file directly, you can use the -i option:

sed -i 's/  */ /g' input.txt
Copy
You can combine this command with the previous one to remove the -jigdo mode-flags and their options, as well as any extra spaces between the remaining mode-flags, in a single command:

sed -i 's/-jigdo[^ ]* [^ ]*//g; s/  */ /g' input.txt
Copy
I hope this helps! Let me know if you have any questions or if there’s anything else I can do for you.
Answered By: Jeremy Burcham