[英]awk/bash quoting: print \ in echo
We need to print out 我们需要打印出来
targetID="123" targetID =“ 123”
AssayID="456", AssayID =“ 456”,
awk -F\", 'BEGIN{FS=",";OFS=",";} {print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$13,$14,$15,$16,$17,$18,$19,$20,$12}' VrtAssay_123_target_456_assay_Detail2.csv > VrtAssay_123_target_456_assay_Detail2_reorder.csv
A. We try: 答:我们尝试:
printf "awk -F"\""," 'BEGIN{FS=\",\";OFS=\",\";} {print \$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$11,\$20,\$12,\$13,\$14,\$15,\$16,\$17,\$18,\$19}' VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail2_average.csv > VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail3.csv"
B. or echo B.或回声
echo "awk -F"\"", 'BEGIN{FS=\",\";OFS=\",\";} {print \$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$11,\$20,\$12,\$13,\$14,\$15,\$16,\$17,\$18,\$19}' VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail2_average.csv > VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail3.csv"
Both give (\\ is gone) 都给(\\走了)
awk -F", 'BEGIN{FS=",";OFS=",";} {print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$13,$14,$15,$16,$17,$18,$19,$20,$12}' VrtAssay_123_target_456_assay_Detail2.csv > VrtAssay_123_target_456_assay_Detail2_reorder.csv
C. If we try C.如果我们尝试
printf "awk -F\\", 'BEGIN{FS=\",\";OFS=\",\";} {print \$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$11,\$20,\$12,\$13,\$14,\$15,\$16,\$17,\$18,\$19}' VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail2_average.csv > VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail3.csv"
These will give an error message of 这些将给出错误消息
Unmatched ".
D. If we try D.如果我们尝试
echo "awk -F\\", 'BEGIN{FS=\",\";OFS=\",\";} {print \$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9,\$10,\$11,\$20,\$12,\$13,\$14,\$15,\$16,\$17,\$18,\$19}' VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail2_average.csv > VrtAssay_${TargetIDs}_target_${AssayID}_assay_Detail3.csv"
This gives us 这给了我们
Unmatched ".
Wonder any guru could kindly offer some solutions? 想知道任何一位上师可以提供一些解决方案吗?
Any of these work, you just need to make sure that everything's escaped properly: 这些工作中的任何一项,您只需要确保所有内容均已正确转义即可:
$ echo 'awk -F\",'
$ echo awk -F\\\",
$ echo "awk -F\\\","
The shell's parsing rules are basically: Shell的解析规则基本上是:
'single quotes'
, everything except for single quotes is interpreted literally; 在'single quotes'
,除单引号外的所有内容均按字面意义进行解释; to include a literal single quote, you need to close the single quote and then use double quotes to get that. 要包括文字单引号,您需要先关闭单引号,然后使用双引号将其括起来。 "double quotes"
, double quotes and backslashes must be escaped with a backslash. 在"double quotes"
,双引号和反斜杠必须以反斜杠转义。 So, a literal double quote is \\"
, a literal backslash is \\\\
, and a literal backslash and double quote are \\\\\\"
. 因此,文字双引号是\\"
,文字反斜杠是\\\\
,文字反斜杠和双引号是\\\\\\"
。 If you just write \\\\"
, that's a literal backslash followed by a closing quote. 如果您只写\\\\"
,那是一个文字反斜杠,后跟一个引号。 使用单引号而不是双引号,例如:
echo 'awk -F\",'
Give a try to, 试试看,
echo 'awk -F\",'
It would print as it is if we enclose the input within single quotes. 如果将输入括在单引号中,它将按原样打印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.