Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 列出的特定分区的偏移量_Bash_Awk - Fatal编程技术网

Bash 列出的特定分区的偏移量

Bash 列出的特定分区的偏移量,bash,awk,Bash,Awk,在这里找到一个问题: 关于使用awk、bash和parted作为GPT分区 作为脚本语言的新手,我不确定是否以及如何基于现有请求构建 我希望获取parted命令列出的特定分区。具体地说,我需要ntfs分区的起始扇区,以便在我的bash脚本中设置mount中的偏移量 root@workstation:/mnt/ewf2# parted ewf1 unit B p Model: (file) Disk /mnt/ewf2/ewf1: 256060514304B Sector size (logic

在这里找到一个问题: 关于使用awk、bash和parted作为GPT分区

作为脚本语言的新手,我不确定是否以及如何基于现有请求构建

我希望获取parted命令列出的特定分区。具体地说,我需要ntfs分区的起始扇区,以便在我的bash脚本中设置mount中的偏移量

root@workstation:/mnt/ewf2# parted ewf1 unit B p
Model:  (file)
Disk /mnt/ewf2/ewf1: 256060514304B
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start End Size File system  Name Flags
 1  1048576B    525336575B     524288000B   fat32  EFI system partition  boot
 2  525336576B  659554303B     134217728B          Microsoft reserved partition  msftres
 3  659554304B  256060162047B  255400607744B ntfs  Basic data partition    msftdata

awk
是您执行此任务的朋友:

$ parted ewf1 unit B p |awk '$5=="ntfs"{print $2}'

当第五列等于ntfs时,打印第二列。

awk
是您执行此任务的朋友:

$ parted ewf1 unit B p |awk '$5=="ntfs"{print $2}'

当第五列等于ntfs时,打印第二列。

这将打印最后一行的第二个字段:

parted ewf1 unit B p | awk 'END { print $2  }'  # prints 659554304B
或者,您可以搜索与
ntfs

parted ewf1 unit B p | awk '/ntfs/ { print $2  }'  # prints 659554304B

这将打印最后一行的第二个字段:

parted ewf1 unit B p | awk 'END { print $2  }'  # prints 659554304B
或者,您可以搜索与
ntfs

parted ewf1 unit B p | awk '/ntfs/ { print $2  }'  # prints 659554304B

grep
与PCRE一起使用:

parted ewf1 unit B p | grep -Po "^\s+[^ ]+\s+\K[^ ]+(?=\s.*ntfs)"
输出:

659554304B

grep
与PCRE一起使用:

parted ewf1 unit B p | grep -Po "^\s+[^ ]+\s+\K[^ ]+(?=\s.*ntfs)"
输出:

659554304B