Results 1 to 3 of 3
I can't figure out how to pull part of a string that I need using awk.
I have a string that looks like this:
Code:
temp=$"buildroot_tag: buildroot_dev_sdev_v2b0064_20111222_dcm"
Using a regex ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-25-2012 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 4
Awk to match string
I can't figure out how to pull part of a string that I need using awk.
I have a string that looks like this:
Using a regex simulator I found I can use:Code:temp=$"buildroot_tag: buildroot_dev_sdev_v2b0064_20111222_dcm"
to extract the value I want: v2b0064_20111222Code:v[0-9][a-fA-F][0-9]*_[0-9]*[^_.*]
I can't assume too much about the string other than it will be something like *_v*b*_SomeDate_*
I've been able to get to the point of extracting just this line from a document but can't figure out how to get just the part of this string I need.
I thought it should be:
but that just spits out the same thing I started with. I want temp to be equal to:Code:temp=$(echo $temp | awk /v[0-9][a-fA-F][0-9]*_[0-9]*[^_.*]/)
v2b0064_20111222
How can I do this?
This works but I don't think I can assume it will always work because the number of fields can vary.
Code:echo $temp | awk -F_ '{print $5 "_" $6}'Last edited by SI_TW; 07-25-2012 at 08:31 PM.
- 07-26-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,687
you could pipe it to sed, and let it do the stripping/substituting:
Code:#!/bin/bash temp=$"buildroot_tag: buildroot_dev_sdev_v2b0064_20111222_dcm" echo $temp |\ awk /v[0-9][a-fA-F][0-9]*_[0-9]*[^_.*]/ |\ sed -e 's|^.*\(v[0-9]b[0-9].*_[0-9]*\)_dcm$|\1|'
- 08-01-2012 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 4
That works great. Thanks


Reply With Quote
