Bookmark and Share

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   Phil Schumm <[email protected]>
To   <[email protected]>
Subject   Re: st: Append the Contents of Fixed Width Text File
Date   Sat, 17 Aug 2013 11:51:08 -0500

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index