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: Append the Contents of Fixed Width Text File
From
Steve Samuels <[email protected]>
To
[email protected]
Subject
Re: st: Append the Contents of Fixed Width Text File
Date
Sat, 17 Aug 2013 14:07:40 -0400
You say you need to append the files together first. Why first?
Something like this should produce the same result.
. save d1, replace emptyok
. foreach f in f1 f2 f3 {
. clear
. infile using dict.txt, using(`f'.txt).
. gen source = "`f'"
. append using d1
. save d1, replace
}
Steve
On Aug 17, 2013, at 12:51 PM, Phil Schumm wrote:
On Aug 17, 2013, at 8:22 AM, Rijo John <[email protected]> wrote:
> I have several large fixed with data files, one for each state. These are data files where each field has a fixed column location and width, rather than having the start and end of the field marked by a delimiter character, as in delimited ASCII files. Usually we write a dictionary program to extract only the columns we want from any given fixed width file. I need to append these together to one large file before I use dictionary on that large file. The appended file should also have a variable indicating which dataset the particular observations originally belonged.
In bash (e.g., OS X or Linux), you could use something like
for f in f1.txt f2.txt f3.txt; do sed -e "s/$/$f/" $f >> out.txt; done
to append the name of the file to the end of each row, and then concatenate the files into one file. I'm sorry, I don't know how to do this in Windows.
-- Phil
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/