Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
redirect text output

Subject: redirect text output

From: Murphy O'Brien

Date: 3 Sep, 2009 14:06:01

Message: 1 of 6


I use "grep" from the file exchange (an excellent function written by us). Does anyone know how I can direct the results to a textfile instead of to the command window. I feel that this is very simple to do, but I can't think of a way (expect of course the clunky DIARY)

Murphy

Subject: redirect text output

From: Yuri Geshelin

Date: 3 Sep, 2009 14:40:23

Message: 2 of 6

"Murphy O'Brien" <murphyobrien@gmail.com> wrote in message <h7oig9$bc7$1@fred.mathworks.com>...
>
> I use "grep" from the file exchange (an excellent function written by us). Does anyone know how I can direct the results to a textfile instead of to the command window. I feel that this is very simple to do, but I can't think of a way (expect of course the clunky DIARY)
>
> Murphy

Hi,

If you use GREP for unix, prefix it with ‘!’ as with any other unix command / program and pipe the output to a file. E.g.,

> !grep search_string input_file(s) > output_file.txt

Note however, that it won’t work for any shell. For example, it works for the csh unix shell, but does not work for bash. I do not know why, but when I need to execute a unix command / program from matlab, I launch matlab from the csh shell. The SYSTEM command does not work in either shell, I tried it.

If you use GREP for windows, it should be the same. I did not verify it for GREP proper, but any DOS command / program gets executed this way, too:

> !command > output_file.txt

Subject: redirect text output

From: Yuri Geshelin

Date: 3 Sep, 2009 14:56:06

Message: 3 of 6

"Murphy O'Brien" <murphyobrien@gmail.com> wrote in message <h7oig9$bc7$1@fred.mathworks.com>...
>
> I use "grep" from the file exchange (an excellent function written by us). Does anyone know how I can direct the results to a textfile instead of to the command window. I feel that this is very simple to do, but I can't think of a way (expect of course the clunky DIARY)
>
> Murphy

My apologies, I did not realize that you used grep from file exchane. Please disregard my previous post.

Yuri

Subject: redirect text output

From: Andy

Date: 3 Sep, 2009 14:57:04

Message: 4 of 6

"Murphy O'Brien" <murphyobrien@gmail.com> wrote in message <h7oig9$bc7$1@fred.mathworks.com>...
>
> I use "grep" from the file exchange (an excellent function written by us). Does anyone know how I can direct the results to a textfile instead of to the command window. I feel that this is very simple to do, but I can't think of a way (expect of course the clunky DIARY)
>
> Murphy

I haven't used it yet, but from the description it looks like you can save the results to a variable. Then you should use any of the MATLAB commands for writing to text files (csvwrite, fprintf, etc.) to save the output how you would like it.

Subject: redirect text output

From: Murphy O'Brien

Date: 4 Sep, 2009 11:12:02

Message: 5 of 6

"Andy " <theorigamist@gmail.com> wrote in message <h7olg0$6ue$1@fred.mathworks.com>...
> "Murphy O'Brien" <murphyobrien@gmail.com> wrote in message <h7oig9$bc7$1@fred.mathworks.com>...
> >
> > I use "grep" from the file exchange (an excellent function written by us). Does anyone know how I can direct the results to a textfile instead of to the command window. I feel that this is very simple to do, but I can't think of a way (expect of course the clunky DIARY)
> >
> > Murphy
>
> I haven't used it yet, but from the description it looks like you can save the results to a variable. Then you should use any of the MATLAB commands for writing to text files (csvwrite, fprintf, etc.) to save the output how you would like it.

It is possible to output to a variable, so I guess that would work. I just thought there was something obvious I was missing.

Murphy

Subject: redirect text output

From: Jan Simon

Date: 4 Sep, 2009 21:55:05

Message: 6 of 6

Dear Murphy O'Brien!

> I use "grep" from the file exchange (an excellent function written by us). Does anyone know how I can direct the results to a textfile instead of to the command window. I feel that this is very simple to do, but I can't think of a way (expect of course the clunky DIARY)

Although I think, the output arguments of GREP should be a better idea, you can catch the output to the command window of any function with EVALC. Storing it to a file should be an easy job afterwards.

Kind regards, Jan

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us