I have the following output:

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

I would like to grep contents under the Expires column The value under this will change from client to client so this will be a variable.

So, regardless of what value is there, I would like to see the output. In this case it should be:

2017-03-26 01:42:53 IST
  • 1
    if your fields are tab-delimited, awk -F'\t' ' $9 ~ /pattern/ {print}' – DopeGhoti Mar 21 '17 at 21:52

It looks like you have a fixed column and then it is:

cut -c121-143 file


Another way to do it if the column with the key word 'Expires' can vary, is by first identify the position of the keyword and then echo from that position and 23 ahead:

#! /bin/bash
# Syntax:
#   ./cut_expires < file
# read first line from stdin
read LINE
# Remove chars from start to 'Expires' inclusive
# Calculate where 'Expires' start
START=$(( ${#LINE}-${#PREFIX}-${#EXPIRES} ))
while read LINE; do
    # echo from character pos $START and 23 characters
    echo ${LINE:$START:23}
| improve this answer | |
  • Unfortunately, the value under this are not fixed. This varies from VM to VM and from machine to machine. Basically I am trying to extent the expiration date via a script by adding days. So the expiration date changes depending on when a backup was taken, so it is never fixed. – suhas savkoor Mar 22 '17 at 12:57
  • I guessed the date could change but does the column also change? The command above is fairly simple, it just take all characters from position 121 to 143. Pls add how line 2 and 3 would look in your original question. – hschou Mar 22 '17 at 13:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.