# How to check a string in a file with not\_if guard interpreator?

**URL:** <https://discourse.chef.io/t/how-to-check-a-string-in-a-file-with-not-if-guard-interpreator/11723>\
**Category:** Chef Infra (archive)\
**Created:** [October 10, 2017, 12:48pm UTC](https://discourse.chef.io/t/how-to-check-a-string-in-a-file-with-not-if-guard-interpreator/11723 "2017-10-10T12:48:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankur760](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@Ankur760](https://discourse.chef.io/u/Ankur760)\
**Post date:** [October 10, 2017, 12:48pm UTC](https://discourse.chef.io/t/how-to-check-a-string-in-a-file-with-not-if-guard-interpreator/11723/1 "2017-10-10T12:48:04Z")

</div>

is their any way so i can check a not\_if “findstr root abc.txt”

---

<div class="post-metadata">

**Author:** ![spuder](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/spuder/32/1382_2.png) [@spuder](https://discourse.chef.io/u/spuder)\
**Post date:** [October 10, 2017, 3:48pm UTC](https://discourse.chef.io/t/how-to-check-a-string-in-a-file-with-not-if-guard-interpreator/11723/2 "2017-10-10T15:48:57Z")

</div>

You could use ruby to check the contents of a file

```
not_if { ::File.readlines(abc.txt).grep(/root/i).empty? }

```

Or a more powershell way, assuming findstr returns proper boolean values

```
powershell_script 'foo' do
  guard_interpreter :powershell_script
  convert_boolean_return true
  not_if "findstr root abc.txt"
end
```

---

<div class="post-metadata">

**Author:** ![Ankur760](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@Ankur760](https://discourse.chef.io/u/Ankur760)\
**Post date:** [October 11, 2017, 7:39am UTC](https://discourse.chef.io/t/how-to-check-a-string-in-a-file-with-not-if-guard-interpreator/11723/3 "2017-10-11T07:39:06Z")

</div>

can i give #{path}

not\_if { ::File.readlines(#{path}).grep(/root/i).empty? }

like this  
beacuse i want to use it in a package resource.
