diff options
author | Darrick J. Wong <djwong@kernel.org> | 2022-10-28 10:42:10 -0700 |
---|---|---|
committer | Zorro Lang <zlang@kernel.org> | 2022-10-30 18:39:20 +0800 |
commit | 1153cd05b98768ba0d26c102232f0e1fc2fb7d74 (patch) | |
tree | 0c6d67fa424cc01af330aa6caddf5da3bdce0cc7 /common/xfs | |
parent | 898ace3b1835553a379822df7386f27961c9cdb3 (diff) |
common: simplify grep pipe sed interactions
Zorro pointed out that the idiom "program | grep | sed" isn't necessary
for field extraction -- sed is perfectly capable of performing a
substitution and only printing the lines that match that substitution.
Do that for the common helpers.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'common/xfs')
-rw-r--r-- | common/xfs | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -179,8 +179,7 @@ _xfs_get_rtextents() { local path="$1" - $XFS_INFO_PROG "$path" | grep 'rtextents' | \ - sed -e 's/^.*rtextents=\([0-9]*\).*$/\1/g' + $XFS_INFO_PROG "$path" | sed -n "s/^.*rtextents=\([[:digit:]]*\).*/\1/p" } # Get the realtime extent size of a mounted filesystem. @@ -188,8 +187,7 @@ _xfs_get_rtextsize() { local path="$1" - $XFS_INFO_PROG "$path" | grep 'realtime.*extsz' | \ - sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g' + $XFS_INFO_PROG "$path" | sed -n "s/^.*realtime.*extsz=\([[:digit:]]*\).*/\1/p" } # Get the size of an allocation unit of a file. Normally this is just the @@ -217,8 +215,7 @@ _xfs_get_dir_blocksize() { local fs="$1" - $XFS_INFO_PROG "$fs" | grep 'naming.*bsize' | \ - sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g' + $XFS_INFO_PROG "$fs" | sed -n "s/^naming.*bsize=\([[:digit:]]*\).*/\1/p" } # Set or clear the realtime status of every supplied path. The first argument @@ -1267,7 +1264,7 @@ _force_xfsv4_mount_options() # Find AG count of mounted filesystem _xfs_mount_agcount() { - $XFS_INFO_PROG "$1" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g' + $XFS_INFO_PROG "$1" | sed -n "s/^.*agcount=\([[:digit:]]*\).*/\1/p" } # Wipe the superblock of each XFS AGs |