Add double quotes into string

Hi,
Can anyone point me to add double quotes into string.I want to prepare command into following way with string.

awk 'BEGIN {printf "x\n%10s\t%10s\n", "Vol", "Current"}{if($1+0==$1){printf "%10.5f\t%10.5f\n", $2, $3}} END {printf "y\n"}'


That's unreadable.

Put the program in a file and call it with:
awk -f prog.awk
Last edited on
"awk 'BEGIN {printf \"x\\n%10s\\t%10s\\n\", "Vol\", \"Current\"}{if($1+0==$1){printf \"%10.5f\\t%10.5f\\n\", $2, $3}} END {printf \"y\\n\"}'"


That is each ( " ) shall be substituted for ( \" ) and each ( \ ) for ( \\ ).
Last edited on
That's even more unreadable. I take one day someone will need to support this, right?
Or you can use a raw string literal introduced in C++ 2011. In this case there is no need to double \ and to use \" instead of ".
I advice to use a raw string literal.

For example

1
2
3
4
5
6
7
8
9
10
#include <iostream> 
#include <string>     

int main()
{
     std::string s( R"(awk 'BEGIN {printf "x\n%10s\t%10s\n", "Vol", "Current"}{if($1+0==$1){printf "%10.5f\t%10.5f\n", $2, $3}} END {printf "y\n"}')" );
     std::cout << s << std::endl;

        return 0;     
}
Last edited on
I advice to use a raw string literal.
In AWK?
@kbw
I advice to use a raw string literal.
In AWK?


In the C++ program.
Hi,
I have tried to Raw string but it did not accept.Do I need any other header file. I added in string file. or as we have legacy header file. do I need update string header file

gcc version:
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)


1
2
3
4
5
6
7
8
9
put.cpp:6: error: `R' was not declared in this scope
put.cpp:6: error: stray '\' in program
put.cpp:6:52: invalid suffix "s" on integer constant
put.cpp:6: error: stray '\' in program
put.cpp:6:58: invalid suffix "s" on integer constant
put.cpp:6: error: stray '\' in program
put.cpp:6: error: stray '\' in program
put.cpp:6: error: stray '\' in program
put.cpp:6: error: stray '\' in program 
Last edited on
No header is required to use raw string literals. It seems that you are using an old compiler that does not support raw string literals.
To be sure that string literals are useful you can check my code on-line at www.ideone.com selecting C++11 ( gcc 4.7.2).
If you have no a possibility to use a newer compiler then you should do as I pointed out in my first post.
Last edited on
Thx a lot for reply . it works for me.
Topic archived. No new replies allowed.