Hi Javad, The example text file you sent doesn't appear to have the two "trailer" lines that you describe. I would try this brute force method as all you seem to want is to multiply the third column values by a constant:
air<-readLines("Air.txt") # define the column 3 field begincol3<-29 endcol3<-42 widthcol3<-14 lenline<-117 for(airline in 1:length(air)) { # is this a data line? if(substr(air[airline]) == " ") air[airline]<-paste0(substr(inputline,1,begincol3-1), formatC(as.double(substr(inputline,begincol3,endcol3))*mult3, digits=5,width=widthcol3,format="f"), substr(inputline,endcol3+1,lenline)) } writeLines(air,"Air2.txt") Jim On Wed, Sep 21, 2022 at 9:25 PM javad bayat <j.bayat...@gmail.com> wrote: > > Dear Jim; > I have no knowledge of the FORTRAN language. The text file is a model's > output file and I know that the format is in FORTRAN. I want to write a text > file exactly similar to the attached text file using R programming. The steps > below show my goal: > 1- Read the text file without the first 8 and last 2 rows as a dataframe. > 2- Double the 3rd column values (or multiply by specific number). > 3- Insert the removed first 8 rows of the original text file as header in the > dataframe. > 4- Insert the last 2 rows of the original text file at the end of dataframe. > 5- Write the dataframe as a new text file exactly similar to the original > text file. > Is it possible? > Sincerely > > > > > > > On Wed, Sep 21, 2022 at 3:29 PM Jim Lemon <drjimle...@gmail.com> wrote: >> >> Hi, >> There was a .txt attachment that is some type of data file. Maybe what >> you mean is can the header be stripped and the rest written out in a >> format that can be input with a FORTRAN read routine. Yes, you just >> have to read it into a data frame and write it out so that it is in >> either free or fixed format. You will have to define the variable >> names in your FORTRAN code and work out the input format >> specifications for the fields. >> >> Jim >> >> On Wed, Sep 21, 2022 at 8:30 PM Ebert,Timothy Aaron <teb...@ufl.edu> wrote: >> > >> > This post was empty. >> > >> > Tim >> > >> > From: R-help <r-help-boun...@r-project.org> On Behalf Of javad bayat >> > Sent: Wednesday, September 21, 2022 2:09 AM >> > To: R-help@r-project.org >> > Subject: [R] Write text file in Fortran format >> > >> > >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. > > > > -- > Best Regards > Javad Bayat > M.Sc. Environment Engineering > Alternative Mail: bayat...@yahoo.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.