# check file script

**URL:** <https://community.unix.com/t/check-file-script/313809>\
**Category:** Shell Programming and Scripting\
**Created:** [July 19, 2012, 5:14am UTC](https://community.unix.com/t/check-file-script/313809 "2012-07-19T05:14:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![arrals\_vl](https://community.unix.com/letter_avatar/arrals_vl/32/6_22734026db12803ebb3e059622ac3534.png) [@arrals\_vl](https://community.unix.com/u/arrals_vl)\
**Post date:** [July 19, 2012, 5:14am UTC](https://community.unix.com/t/check-file-script/313809/1 "2012-07-19T05:14:12Z")

</div>

hi,

i have a small file with 4 rows that looks like this:

any\_error\_today=  
any\_message\_today=  
any\_other\_thing=  
any\_other \_thing=

I want to write a script that checks if after any = there is no data(is empty), then everything is OK.  
If after = there is data written, for example "any\_error\_today= could not load file", then  
the script says "not OK", and prints out the row with problem. In this case: "any\_error\_today= could not load file"

Thank you very much!

Ervin

---

<div class="post-metadata">

**Author:** ![elixir\_sinari](https://community.unix.com/user_avatar/community.unix.com/elixir_sinari/32/2563_2.png) [@elixir\_sinari](https://community.unix.com/u/elixir_sinari)\
**Post date:** [July 19, 2012, 5:29am UTC](https://community.unix.com/t/check-file-script/313809/2 "2012-07-19T05:29:40Z")

</div>

```nohighlight
grep '=..*' inputfile

```

---

<div class="post-metadata">

**Author:** ![arrals\_vl](https://community.unix.com/letter_avatar/arrals_vl/32/6_22734026db12803ebb3e059622ac3534.png) [@arrals\_vl](https://community.unix.com/u/arrals_vl)\
**Post date:** [July 19, 2012, 5:40am UTC](https://community.unix.com/t/check-file-script/313809/3 "2012-07-19T05:40:30Z")

</div>

Hi, thank you for your reply.  
I want to write a little script for this purpose.  
Better is in perl, but also with awk is ok.

Thank you in advance!

---------- Post updated at 04:40 AM ---------- Previous update was at 04:35 AM ----------

i have done this so far:

#!/usr/bin/perl -w  
use strict;  
use warnings;

open FIL, '\<myfile';  
my $line = \<FIL\>;  
close FIL;

if ($line = ){  
print "Everything OK";  
}else{  
print "$line\n";  
}

BUT, this line is not ok if ($line = ). how to tell after = is emty?

thnx

---

<div class="post-metadata">

**Author:** ![elixir\_sinari](https://community.unix.com/user_avatar/community.unix.com/elixir_sinari/32/2563_2.png) [@elixir\_sinari](https://community.unix.com/u/elixir_sinari)\
**Post date:** [July 19, 2012, 5:44am UTC](https://community.unix.com/t/check-file-script/313809/4 "2012-07-19T05:44:32Z")

</div>

```nohighlight
grep '=..*' inputfile || echo "Everything OK"

```

---

<div class="post-metadata">

**Author:** ![arrals\_vl](https://community.unix.com/letter_avatar/arrals_vl/32/6_22734026db12803ebb3e059622ac3534.png) [@arrals\_vl](https://community.unix.com/u/arrals_vl)\
**Post date:** [July 19, 2012, 5:55am UTC](https://community.unix.com/t/check-file-script/313809/5 "2012-07-19T05:55:34Z")

</div>

Can you write it in perl please?

---

<div class="post-metadata">

**Author:** ![elixir\_sinari](https://community.unix.com/user_avatar/community.unix.com/elixir_sinari/32/2563_2.png) [@elixir\_sinari](https://community.unix.com/u/elixir_sinari)\
**Post date:** [July 19, 2012, 6:07am UTC](https://community.unix.com/t/check-file-script/313809/6 "2012-07-19T06:07:13Z")

</div>

Is this homework???

When a simple grep does the job, why use perl?

If you need awk, then the following will work:

```nohighlight
awk '!/\=$/{p=1;print} END{if (!p) print "Everything OK"}' inputfile

```

Don't know perl...

---

<div class="post-metadata">

**Author:** ![Skrynesaver](https://community.unix.com/user_avatar/community.unix.com/skrynesaver/32/14143_2.png) [@Skrynesaver](https://community.unix.com/u/Skrynesaver)\
**Post date:** [July 19, 2012, 6:15am UTC](https://community.unix.com/t/check-file-script/313809/7 "2012-07-19T06:15:47Z")

</div>

```nohighlight
~/$ cat ~/tmp/tmp.dat
any_error_today=
any_message_today=
any_other_thing=
any_other_thing= Out of cheese error ++REDO FROM START++
any_other _thing=

~/$ egrep '=.+$' ~/tmp/tmp.dat
any_other_thing= Out of cheese error ++REDO FROM START++

```

So something like this

```nohighlight
errors=$(egrep '=.+$' ~/tmp/tmp.dat);if ["X$errors" == "X"]; then echo "OK";else echo $errors;fi

```

---------- Post updated at 11:15 AM ---------- Previous update was at 11:12 AM ----------

Or the whole thing in Perl

```nohighlight
 perl -ne 'if (/=.+$/){$err++;print }END{print "OK\n" if ! $err}' ~/tmp/tmp.dat
any_other_thing= Out of cheese error ++REDO FROM START++

```
