0

This is the grep command I used

grep -ic address log*

The output is 0. I know for a fact that there are more than 60 occurrences of the word address in the log file. But I still get 0.

Now, I copied the contents of the log into a new file log2

 grep -ic address log2 

outputs 65! I copied the contents by selecting all and copy pasting instead of the cp command. I checked and made sure the file permissions were all fine.

ls -l show this

-rwxrwxrwx 1 root    root              91694 Jul 26 16:18 log

-rw-r--r-- 1 root    root              45220 Jul 30 14:16 log2*

The only discrepancy I can see is that the first log is twice the size of its copy. Is this a format issue?

When I open the file in vim it shows

[converted][dos] as the format.

How can I fix this?

Any help is appreciated.

alexander.polomodov
  • 1,068
  • 3
  • 10
  • 14
searcot jabali
  • 281
  • 1
  • 2
  • 6

1 Answers1

1

As your file log is twice as big as log2, but should be an exact copy, it is likely that is it encoded in UCS-2. Did the file originate on Windows?

Try

file log log2

Edit:
The output of file in the comment confirms this.

Use this for transparent grep

recode ucs2..utf8 < log | grep ...

Or this to convert the file

recode ucs2..utf8 log
grep ... log
RalfFriedl
  • 3,108
  • 4
  • 13
  • 17
  • Ralf:- `log: Little-endian UTF-16 Unicode text, with very long lines, with CRLF, CR line terminators log2: ASCII text, with very long lines` – searcot jabali Jul 31 '18 at 06:33