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.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With