Grep 特定の列 [重複]

Grep 特定の列 [重複]

次の出力があります。

Created                 LabelNum Size   Retention Hostname                Location Label           Plugin               Expires                 Server
----------------------- -------- ------ --------- ----------------------- -------- --------------- -------------------- ----------------------- -------------------------------
2017-03-22 01:43:29 IST 9        1.0 GB DW        vdp-dest.happycow.local Local    A-1490127173251 Windows VMware Image 2017-03-26 01:42:53 IST DD - data-domain.happycow.local

その列Expiresの下の値はクライアントごとに異なるため、これは変数になります。

したがって、価値があるものは何でも結果を見たいです。この場合、次のようになります。

Expires
-----------------------
2017-03-26 01:42:53 IST

ベストアンサー1

固定列があるようです。それでは、次のようになります。

cut -c121-143 file

編集する:

キーワード「Expires」を含む列が異なる場合は、代わりにキーワードの位置を識別し、その場所で23をエコーし​​て渡すことです。

#! /bin/bash
# Syntax:
#   ./cut_expires < file
#
# read first line from stdin
read LINE
# Remove chars from start to 'Expires' inclusive
PREFIX=${LINE/*Expires/}
EXPIRES=Expires
# Calculate where 'Expires' start
START=$(( ${#LINE}-${#PREFIX}-${#EXPIRES} ))
echo $EXPIRES
while read LINE; do
    # echo from character pos $START and 23 characters
    echo ${LINE:$START:23}
done

おすすめ記事