Page 1 of 1

Extract string from a column

Posted: 2016/05/24 12:11:01
by Kinjal
Hi,
I have record with three columns
ID TYPE Deal
01 A Member Since Year-2015
02 B Member Since Year-2014
03 A Member Since Year-2014
I only want year part from field Deal How to write a query?
Thanks,

Re: Extract string from a column

Posted: 2016/05/24 23:17:38
by TrevorH
This isn't really a CentOS problem as such so I've moved it to the social forum for want of anywhere better to put it.

How are the columns separated?

Re: Extract string from a column

Posted: 2016/05/25 02:44:42
by drk
Kinjal wrote:Hi,
I have record with three columns
ID TYPE Deal
01 A Member Since Year-2015
02 B Member Since Year-2014
03 A Member Since Year-2014
I only want year part from field Deal How to write a query?
Thanks,
$ awk -F- '{print $NF}' /path/to/file

Just one way

Re: Extract string from a column

Posted: 2016/05/25 07:18:15
by giulix63
Another way:

Code: Select all

grep -Eo Year-[0-9]{4} /path/to/file |grep -Eo [0-9]{4}

Re: Extract string from a column

Posted: 2016/05/25 15:53:40
by aks
cut -d'-' -f 2- <file>

Re: Extract string from a column

Posted: 2016/05/26 05:25:30
by drk
sed 's!.*r-!!' /path/to/file