![Grep 특정 열 [중복]](https://linux55.com/image/108002/Grep%20%ED%8A%B9%EC%A0%95%20%EC%97%B4%20%5B%EC%A4%91%EB%B3%B5%5D.png)
다음과 같은 출력이 있습니다.
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