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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk question

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL

is the "$" used in command ok for this case (I want to find only lines having in 2nd column exact number after a letter

Code:
$ echo "A:C62:BCD:V\nB:D6:DEF:V"
A:C62:BCD:V
B:D6:DEF:V
$ echo "A:C62:BCD:V\nB:D6:DEF:V"|awk -F\: -va=V -vb=6 '$NF==a&&$2~b'
[s]A:C62:BCD:V[/s]
B:D6:DEF:V
$ echo "A:C62:BCD:V\nB:D6:DEF:V"|awk -F\: -va=V -vb=6 '$NF==a&&$2~b[COLOR=#CC0000]"$"[/color]'
B:D6:DEF:V
$
 
Hi

Yes. As concatenation has higher precedence than matching, your code is correct.

But someone will probably suggest you to enclose the concatenation in parenthesis ( () ) to improve readability :
Code:
awk -F\: -va=V -vb=6 '$NF==a&&$2~[red]([/red]b"$"[red])[/red]'

Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top