# Finding exact match string

**URL:** <https://community.unix.com/t/finding-exact-match-string/268607>\
**Category:** Shell Programming and Scripting\
**Created:** [June 30, 2010, 5:31am UTC](https://community.unix.com/t/finding-exact-match-string/268607 "2010-06-30T05:31:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luckybalaji](https://community.unix.com/letter_avatar/luckybalaji/32/6_22734026db12803ebb3e059622ac3534.png) [@luckybalaji](https://community.unix.com/u/luckybalaji)\
**Post date:** [June 30, 2010, 5:31am UTC](https://community.unix.com/t/finding-exact-match-string/268607/1 "2010-06-30T05:31:16Z")

</div>

Hi All,

I'm writing unix script, it should find exact matching in search string. Looks simple but when i started i'm stuck to find the exact match character string.

The unix script reads the records from DB Table. The table will have values something likes these

```nohighlight
Feed : A Feed File name : feed_file_yyyymmdd.txt  
Feed : B Feed file Name : feed_file1_yymmdd.txt
Feed : C Feed file Name : feed_file2_yyyymmmdd.txt

```

For the Feed A, I have to look feed file name in "feed\_file\_20100630.txt", for B "feed\_file1\_100630.txt", for C "feed\_file2\_2010Jun30.txt". For the tomorrow month and Data gets changed (tomorrow is 1 Jul 2010).

After reading these values from DB, i have to find what format it has and replace with as of today's date format, look the file is exist in share folder.

I try to implement this with awk

```nohighlight
awk ' {
/yyyymmdd/ { #case 1; next }
/yymmdd/ { #case 2; next }
#for all possible formats
}'

```

for the Feed B it goes to Case 1, but it suppose to go to Case 2.

If i reverse the order for the Feed A, it suppose to go to case 1, but goes to case 2.

I'm unable to achieve this using "-w" option in "grep" command.

I hope i have explained clearly.

Let me know how to resolve my problem

---

<div class="post-metadata">

**Author:** ![bartus11](https://community.unix.com/user_avatar/community.unix.com/bartus11/32/1418_2.png) [@bartus11](https://community.unix.com/u/bartus11)\
**Post date:** [June 30, 2010, 5:38am UTC](https://community.unix.com/t/finding-exact-match-string/268607/2 "2010-06-30T05:38:10Z")

</div>

I don't know if I understood you correctly, but can't you do it like that?

```nohighlight
awk ' {
/_yyyymmdd/ { #case 1; next }
/_yymmdd/ { #case 2; next }
#for all possible formats
}'

```

---

<div class="post-metadata">

**Author:** ![luckybalaji](https://community.unix.com/letter_avatar/luckybalaji/32/6_22734026db12803ebb3e059622ac3534.png) [@luckybalaji](https://community.unix.com/u/luckybalaji)\
**Post date:** [June 30, 2010, 6:35am UTC](https://community.unix.com/t/finding-exact-match-string/268607/3 "2010-06-30T06:35:18Z")

</div>

Actually in my example i have used "\_" before for all date format. But actually some cases it is like (yyyymmdd\_fee\_file2.dat). In some cases it is like hh\_mm\_ss:yyyymmmdd also. So this wouldnt work out for my problem.

I have somehow close to my solution using the re interval option to awk. If some1 has better solution. Warm welcome for it.

echo $feed\_file | awk --re-interval '  
/y{3}ymmdd/ { print "yyyymmdd" }  
/[^y]y{1}ymmdd/ { print "yymmdd" }  
/yymmmdd/ { print "yymmmdd" }  
/y{3}ymmmdd/ { print "yyyymmmdd" }  
'

like this i will add complete possible cases. If any new format in feed file, i will be keep updating this script

---

<div class="post-metadata">

**Author:** ![bartus11](https://community.unix.com/user_avatar/community.unix.com/bartus11/32/1418_2.png) [@bartus11](https://community.unix.com/u/bartus11)\
**Post date:** [June 30, 2010, 6:40am UTC](https://community.unix.com/t/finding-exact-match-string/268607/4 "2010-06-30T06:40:08Z")

</div>

Then try:

```nohighlight
awk ' {
/yyyymmdd/ { #case 1; next }
/[^y]yymmdd/ { #case 2; next }
#for all possible formats
}'

```
