文件mkisofs
具有以下一行字符串:
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
我需要删除每个模式标志及其以“-jidgo”开头的选项。这是我正在编写的脚本的一部分。首选本地或 sed 选项,但愿意扩展资源来完成工作。
将每个模式标志放在单独的行上然后运行后,我能够删除它们:
sed -i 's/-jigdo-[^-]*//' mkisofs
sed -i 's/-jigdo[^-]*//' mkisofs
如果保留为一根字符串,则此方法不起作用。我还必须创建两个命令,因为它只会对“jigdo-exclude”进行部分删除。
为了获得更好的视图,每行间隔后的样子如下:
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
当修改为单行字符串时,它应该是这样的:
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
答案1
除非我忽略了某些事情,否则这似乎与我所做的一些测试相符:
sed -i -r 's/-jigdo[^ ]+ [^ ]+ //g' filename
答案2
我问了 Bing AI 我的问题。这是有效的...
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.