-1

I want to check that particular string "20040213_25049.XXXX" containing XXXX or not on other hand when do I write string like "20040213_25049 .XXXX" then it is matched but I want to match with "20040213_25049.XXXX"

echo "20040213_25049 .XXXX" | awk '{match($2,/XXXX/,a)}END{print a[0]}' (It is working)
echo "20040213_25049.XXXX" | awk '{match($2,/XXXX/,a)}END{print a[0]}' (It is not working)

I didn't get any output from above line.

user2932003
  • 171
  • 2
  • 4
  • 14
  • 1
    You are matching the second field. There is no second field.... I am guessing that you have just copied this code and have absolutely no idea how it works at all. Look [here](https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html) –  Mar 16 '15 at 09:39
  • JID@thnx for ur reply basically I'm trying to match sub-string XXXX with "20040213_25049.XXXX" but not able to match on other hand when do I write like this "20040213_25049 .XXXX" then I'm able to match. – user2932003 Mar 16 '15 at 09:50
  • What is it you are looking for to get as an output/result? `yes/no`, the `XXXX` itself? or does `XXXX` represent a number you like to get? – Jotne Mar 16 '15 at 09:52
  • I know what you are trying to do. If you look at the link i posted and actually have a basic understanding of how awk works then you would be able to do it. –  Mar 16 '15 at 09:53
  • 2
    @Jotne They have clearly put in no effort at all and don't even understand the concept of fields in awk. –  Mar 16 '15 at 09:54

1 Answers1

0

You can do some like this:

echo "20040213_25049.XXXX" | awk '/[0-9]{8}_[0-9]{5}\.XXXX/ {print "yes"}'
yes

It will test if you have 5 digits followed by a . and 4 X

Or like this?

echo "20040213_25049.XXXX" | awk '/20040213_25049\.XXXX/ {print "yes"}'
yes

echo "20040213_25049. XXXX" | awk '/20040213_25049\.XXXX/ {print "yes"}'
Jotne
  • 40,548
  • 12
  • 51
  • 55
  • Not even remotely what OP asked for.Mybe you should wait for them to answer your question instead of rushing to answer for imaginary points. –  Mar 16 '15 at 10:04
  • @JID it does this `I want to check that particular string "20040213_25049.XXXX" containing XXXX or not` – Jotne Mar 16 '15 at 10:20
  • It doesn't `Is there a way to print a regexp match with AWK?` –  Mar 16 '15 at 10:22