Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Calling Linux's "cat" command using -shell- in Stata MP 12
From
Phil Clayton <[email protected]>
To
[email protected]
Subject
Re: st: Calling Linux's "cat" command using -shell- in Stata MP 12
Date
Tue, 5 Jun 2012 16:52:39 +1000
I haven't got my Linux installation in front of me but on the Mac each -shell- command runs independently, starting its own session - so the "cd" from the first command won't apply to the second command.
Try something this instead:
* begin code
shell cd ~/data/txt/board_ownership; cat *_2.txt > board_ownership.txt
* end code
Phil
On 05/06/2012, at 4:30 AM, Richard Herron wrote:
> I am trying to use -shell- in Stata MP 12 to call "cat" in Linux to
> concatenate a directory of 800 tab-delimited text files. The
> tab-delimited text files all end in _2.txt and should match the wild
> card *_2.txt. I tried two variants, which both fail. First I tried:
>
> * begin code
> shell cd ~/data/txt/board_ownership
> shell cat *_2.txt > board_ownership.txt
> * end code
>
> which fails with "cat: *_2.txt: No such file or directory". However,
> in the Stata console, if I -shell- to get the command prompt, then I
> can successfully issue the "cd" and "cat" commands. I get the same
> result if I replace the wild card * with an existing file.
>
> Second I tried
>
> * begin code
> shell cat "~/data/txt/board_ownership/*_2.txt" >
> "~/data/txt/board_ownership/board_ownership.txt"
> * end code
>
> which fails with "/bin/bash:
> ~/data/txt/board_ownership/board_ownership.txt: No such file or
> directory"
>
> Can I automate this from within Stata? Or is this best done explicitly
> in the command line?
>
> Thanks!
>
> Richard Herron
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/