- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all!
I have a text file with some data (file1) and i want to create a clone of it (file2) but with some additional lines. How I can do this? Is there any way to shift the lines?
Example files with line numbering are:
---------------
File1.dat
---------------
1: 0 1 2 3 4
2: 1 2 3 4 5
3: 2 3 4 5 6
4: 6 7 8 9 10
I want to create File2 like this:
---------------
File2.dat
---------------
1: 0 1 2 3 4
2: 1 2 3 4 5
3: * * *
4: 2 3 4 5 6
5: 6 7 8 9 10
I have a text file with some data (file1) and i want to create a clone of it (file2) but with some additional lines. How I can do this? Is there any way to shift the lines?
Example files with line numbering are:
---------------
File1.dat
---------------
1: 0 1 2 3 4
2: 1 2 3 4 5
3: 2 3 4 5 6
4: 6 7 8 9 10
I want to create File2 like this:
---------------
File2.dat
---------------
1: 0 1 2 3 4
2: 1 2 3 4 5
3: * * *
4: 2 3 4 5 6
5: 6 7 8 9 10
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use a text editor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have more than 1000 files to edit!!!!!!!!!!!!! And, I want to insert different data lines in each file!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use line-oriented editors, such as edlin (still available in Windows XP-32) or the Unix ed (available for Windows). You also need a system for associating files with lines to enter. Once you have that thought out and ready, batch files will do it.
You can also write a program to do the job, if that is more convenient.
With that many files, you must take precautions to back out if something goes wrong.
You can also write a program to do the job, if that is more convenient.
With that many files, you must take precautions to back out if something goes wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"You can also write a program to do the job, if that is more convenient."
That was my question!!!!!! What is the suitable intrinsic command in fortran to do this manipulation automatically!!!!
That was my question!!!!!! What is the suitable intrinsic command in fortran to do this manipulation automatically!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran has no "intrinsic command" to manipulate lines of text, but one can certainly write a program to do the task that you described. If there were intrinsic commands to do every manipulation that one could think of, the language would be so big that it would be impossible to learn.
I should state that your expectation of a manipulation being done automatically, given that you have not yet given an unambiguous specification of the manipulation, is an unreasonable expectation.
I should state that your expectation of a manipulation being done automatically, given that you have not yet given an unambiguous specification of the manipulation, is an unreasonable expectation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As the others have indicated, there is no special feature in Fortran to shift lines in a file. Nor in any
programming language that I know of. What you want is quite possible:
Read the file line by line and write the lines into a new file, with some extra write statements in between
for the extra lines you want.
But if you want to automate that, then you will have to have an algorithm by which to decide when to insert
these extra lines and what they should contain.
Here is a trivial example (it assumes the lines are no longer than 80 characters and trailing blanks
are unimportant):
character(len=80) :: line
integer :: ierr, count
open( 10, file = 'file1' )
open( 20, file = 'file2' )
count = 0
do
read( 10, '(a)', iostat = ierr) line
count = count + 1
if ( ierr /= 0 ) exit
if ( count == 3 ) write( 20, '(a)' ) '****** extra line *****'
write( 20, '(a)' ) trim(line)
enddo
close( 10 )
close( 20 )
Regards,
Arjen
programming language that I know of. What you want is quite possible:
Read the file line by line and write the lines into a new file, with some extra write statements in between
for the extra lines you want.
But if you want to automate that, then you will have to have an algorithm by which to decide when to insert
these extra lines and what they should contain.
Here is a trivial example (it assumes the lines are no longer than 80 characters and trailing blanks
are unimportant):
character(len=80) :: line
integer :: ierr, count
open( 10, file = 'file1' )
open( 20, file = 'file2' )
count = 0
do
read( 10, '(a)', iostat = ierr) line
count = count + 1
if ( ierr /= 0 ) exit
if ( count == 3 ) write( 20, '(a)' ) '****** extra line *****'
write( 20, '(a)' ) trim(line)
enddo
close( 10 )
close( 20 )
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pick one of your files at random. How will you recognise whether you have correctly added the required data to it or not?
Are they all text files of data with fixed record lengths?
I must admit I am intrigued as to why you have to do this to 1000's of files. Did someone forget something?
Are they all text files of data with fixed record lengths?
I must admit I am intrigued as to why you have to do this to 1000's of files. Did someone forget something?
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page