Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk delimeter

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
0
0
PL

how to explain that awk in red doesn't return version numbers?
is it caused by ++- in the variable?
is it possible to get it working with the variable?


Code:
$ A="libstdc++-devel"
$ rpm -qa|grep ^${A}-[0-9]
libstdc++-devel-3.3.2-5
[red]$ rpm -qa|grep ^${A}-[0-9]|awk -F "${A}" '{print $2}'|cut -d- -f2-[/red]

$ A="zlib"
[green]$ rpm -qa|grep ^${A}-[0-9]|awk -F "${A}" '{print $2}'|cut -d- -f2-[/green]
1.2.5-1
$
 
Hi

The [tt]FS[/tt] ( field separator ) is a regular expression and [tt]+[/tt] is quantifier ( meaning previous entity 1 or more times ) in regular expressions.

You have to escape it : [tt]awk -F "libstdc\\\\+\\\\+-devel" '{print $2}'[/tt]

Or using variable A : [tt]awk -F "${A//+/\\\\+}" '{print $2}'[/tt]

Tested in Bash and MKsh. ( In Bash 3 backslashes ( \ ) are enough, 4 works in both. )

Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top