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:
remove unwanted lines and append important data

Subject: remove unwanted lines and append important data

From: PK

Date: 9 Jan, 2013 03:09:10

Message: 1 of 4

I have multiple text files(say ..5000) and each file has 9 line header,1 line of actual data and 1 footer. I want to remove the headers and footers and creat a seperate text file which would include actual data.

note - actual data has mixed format...

anybody????

Subject: remove unwanted lines and append important data

From: TideMan

Date: 9 Jan, 2013 04:01:07

Message: 2 of 4

On Wednesday, January 9, 2013 4:09:10 PM UTC+13, PK wrote:
> I have multiple text files(say ..5000) and each file has 9 line header,1 line of actual data and 1 footer. I want to remove the headers and footers and creat a seperate text file which would include actual data.
>
>
>
> note - actual data has mixed format...
>
>
>
> anybody????

Something like:
pth='d:\Path to my files\'; % need to include final \
d=dir([pth '*.txt']); % Look for the filenames
fout=fopen([pth 'NewFile.txt'],'wt'); % Open a file for output
for ifile=1:length(d)
   fid=fopen([pth d(ifile).name],'rt');
   % Read first 10 lines, but only retain the 10th
   for iline=1:10
       line=fgetl(fid);
   end
   fclose(fid);
   % Write this line to the output file
   fprintf(fout,'%s\n',line);
end
fclose(fout);

Subject: remove unwanted lines and append important data

From: PK

Date: 9 Jan, 2013 23:24:10

Message: 3 of 4

"PK" wrote in message <kcin0m$kim$1@newscl01ah.mathworks.com>...
> I have multiple text files(say ..5000) and each file has 9 line header,1 line of actual data and 1 footer. I want to remove the headers and footers and creat a seperate text file which would include actual data.
>
> note - actual data has mixed format...
>
> anybody????

thanks TideMan..you're a legend....it works ...

Subject: remove unwanted lines and append important data

From: PK

Date: 10 Jan, 2013 06:31:08

Message: 4 of 4

"PK" wrote in message <kcin0m$kim$1@newscl01ah.mathworks.com>...
> I have multiple text files(say ..5000) and each file has 9 line header,1 line of actual data and 1 footer. I want to remove the headers and footers and creat a seperate text file which would include actual data.
>
> note - actual data has mixed format...
>
> anybody????


what if the text file has header -4 lines
                                datalines-unknown
                                 Footer- 6 lines and starts with line ", , , , ,"- excluding inverted commas
                                   

Tags for this Thread

No tags are associated with 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