6

I have a MSSQL database dump I'm trying to grep through. However, grep does not seem to work on it, at all. Here is a snippet of the file.

...
    ALTER DATABASE [Documents] SET RECURSIVE_TRIGGERS OFF
    GO
    ALTER DATABASE [Documents] SET  DISABLE_BROKER
    GO
    ALTER DATABASE [Documents] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
...

However when I do a grep on it I get nada.

$ cat Documents.sql | grep -i 'alter'
$ <nothing>
$ cat Documents.sql | grep -i 'go'
$ <nothing>

For giggles I created another document 'tempfile' with:

$ cat tempfile 
alter

Alter

ALTER
$

And ran the same grep on it:

$ cat tempfile | grep -i 'alter'
alter
Alter
ALTER

Thoughts on why grep wouldn't work on certain files? Concerns me that when I have to grep through a bunch of stuff to find a small nugget, it 'may' be missing something. Thoughts?

1
  • 9
    I suspect the file is not in UTF-8 since it came from a Windows system. – Michael Hampton Oct 18 '16 at 19:00
7

Ahh. Thank you.

$ file -bi Documents.txt
text/plain; charset=utf-16le
$ vi Documents.txt

set encoding=utf-8
set fileencoding=utf-8

$ file -bi Documents.txt
text/plain; charset=utf-8
$ cat Documents.txt | grep -i 'alter'
ALTER DATABASE [Documents] SET COMPATIBILITY_LEVEL = 120
ALTER DATABASE [Documents] SET ANSI_NULL_DEFAULT OFF 
ALTER DATABASE [Documents] SET ANSI_NULLS OFF 
ALTER DATABASE [Documents] SET ANSI_PADDING OFF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.