Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output (using the write statement) an apostrophe " ' "?

I want to use system command in Fortran 90 for executing folowing 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 which are enclosed between apostrophes and my variable should also be consisting of apostrophes. I don't know how to type it in Fortran 90.

like image 372
Mubeena Shaikh Avatar asked Dec 06 '25 04:12

Mubeena Shaikh


2 Answers

Just use two apostrophes in a row inside the string

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

Additionally, because I did not notice filename1 and filename2 are variables, you must append them as chw21 shows:

 // trim(filename1)//' > '//trim(filename2)
like image 62
Vladimir F Героям слава Avatar answered Dec 07 '25 18:12

Vladimir F Героям слава


You can try to use a parameter for single quotes, like this:

character, parameter :: sq = "'"

Then you can chain things together 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 do at all is using the Hollerith format instruction:

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

That's why I'm not even telling you. Oh.

like image 32
chw21 Avatar answered Dec 07 '25 20:12

chw21



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!