Search code examples
macosunixgrepgarbage

Unix grep command outputs garbage


I´m executing the following command "grep bruno < bash.txt " which gives me the right output "bruno" and garbage "\f0\fs24 \cf0".

I´m on the command shell on a Mac OS X v10.6.8 and i´m pretty sure i should be getting the line of the found word and the word. Not garbage.

This is the Output:

Mobile-Devs-MacBook-Pro:Screenshots Poupe mdev$ grep bruno < bash.txt  
\f0\fs24 \cf0 bruno\

In bash.txt i only have written "bruno", if i output with "cat bash.txt" it also gives me the following garbage:

Mobile-Devs-MacBook-Pro:Screenshots Poupe mdev$ cat bash.txt
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural

\f0\fs24 \cf0 bruno\

If i make "echo bruno > bash.txt" and then "cat bash.txt" it gives me a clean output. Why am i not seeing a clean output when i write the file by hand?


Solution

  • Your file isn't a plain text file. It is RTF. grep is giving you the line containing "bruno", along with the rich text formatting.

    When you do:

    echo bruno > bash.txt
    

    bash.txt contains only "bruno".

    When you "edit the file by hand", your editor is saving as RTF. You need to save as plain text.

    Plain Text