How do I output (using the notation operator) the apostrophe "?"?

I want to use a system command in Fortran 90 to execute the following command:

command =  awk '{print "C"NR,$1,$2,$3}' filename1 > filename2
call system(trim(command))

      

here my filename1 and filename2 are variables in a Fortran 90 program. But the problem is that any character can be assigned to a variable surrounded by apostrophes, and my variable must also consist of apostrophes. I don't know how to introduce it to Fortran 90.

+3


source to share


2 answers


Just use two apostrophes on a line within a line

command =  'awk ''{print "C"NR,$1,$2,$3}'' filename1 > filename2'

      



Also, since I didn't notice that filename1

u filename2

are variables, you should add them as chw21 shows:

 // trim(filename1)//' > '//trim(filename2)

      

+6


source


You can try using the parameter for single quotes, for example:

character, parameter :: sq = "'"

      

Then you can chain things like this:

command = 'awk '//sq//'{print "C"NR,$1,$2,$3}'//sq//' '// &
           trim(filename1)//' > '//trim(filename2)

      

Or, you can swap between single and double quoted strings:



command = "awk '" // '{print "C"NR,$1,$2,$3}' // "' " // &
           trim(filename1) // ' > ' // trim(filename2)

      

What you shouldn't be doing at all is using the Hollerith format statement:

     write(command, 100) trim(f1), trim(f2)
100  FORMAT(29Hawk '{print "C"NR,$1,$2,$3}' , A, " > ", A)

      

This is why I am not even telling you. ABOUT.

+4


source







All Articles