Skip to main content
added 118 characters in body
Source Link
QuartzCristal
  • 2.1k
  • 5
  • 25

Your issue seems to be with the \" you are using.

  1. Once you start a quoted string with" it goes to the next (unquoted) ". A \" inserted inside the quoted string will not terminate that qouted string but will be inserted "as is", i. e.: a double quote character.

  2. Inside a quoted string the $n values are not expanded.

$ echo "one two three" | awk '{print "$2,$3"}'
$2,$3

$ echo "one two three" | awk '{print "\"$2,$3\""}'
"$2,$3"

$ echo "one two three" | awk '{print "\"",$2,$3,"\""}'   # concatenated quotes
" two three "

$ echo "one two three" | awk '{print "\"" $2 $3 "\""}'   # only one string
"twothree"

$ echo "one two three" | awk '{print "\""$2,$3"\""}'     # two strings
"two three"

$ echo "one two three" | awk '{print "\""$2"\"","\""$3"\""}'  # Using OFS
"two" "three"

$ echo "one two three" | awk -vOFS="," '{print "\""$2"\"","\""$3"\""}' # Changing OFS
"two","three"

Those are some possible uses of the \" string inside awk.

So, you probably want this:

awk -F'\t' '{print "\"<li>" $2 "(" $3 ")</li>\""}' OFS='","' datafile.csv

Your issue seems to be with the \" you are using.

  1. Once you start a quoted string with" it goes to the next (unquoted) ". A \" inserted inside the quoted string will not terminate that qouted string but will be inserted "as is", i. e.: a double quote character.

  2. Inside a quoted string the $n values are not expanded.

$ echo "one two three" | awk '{print "$2,$3"}'
$2,$3

$ echo "one two three" | awk '{print "\"$2,$3\""}'
"$2,$3"

$ echo "one two three" | awk '{print "\"",$2,$3,"\""}'   # concatenated quotes
" two three "

$ echo "one two three" | awk '{print "\"" $2 $3 "\""}'   # only one string
"twothree"

$ echo "one two three" | awk '{print "\""$2,$3"\""}'     # two strings
"two three"

$ echo "one two three" | awk '{print "\""$2"\"","\""$3"\""}'  # Using OFS
"two" "three"

$ echo "one two three" | awk -vOFS="," '{print "\""$2"\"","\""$3"\""}' # Changing OFS
"two","three"

Those are some possible uses of the \" string inside awk.

Your issue seems to be with the \" you are using.

  1. Once you start a quoted string with" it goes to the next (unquoted) ". A \" inserted inside the quoted string will not terminate that qouted string but will be inserted "as is", i. e.: a double quote character.

  2. Inside a quoted string the $n values are not expanded.

$ echo "one two three" | awk '{print "$2,$3"}'
$2,$3

$ echo "one two three" | awk '{print "\"$2,$3\""}'
"$2,$3"

$ echo "one two three" | awk '{print "\"",$2,$3,"\""}'   # concatenated quotes
" two three "

$ echo "one two three" | awk '{print "\"" $2 $3 "\""}'   # only one string
"twothree"

$ echo "one two three" | awk '{print "\""$2,$3"\""}'     # two strings
"two three"

$ echo "one two three" | awk '{print "\""$2"\"","\""$3"\""}'  # Using OFS
"two" "three"

$ echo "one two three" | awk -vOFS="," '{print "\""$2"\"","\""$3"\""}' # Changing OFS
"two","three"

Those are some possible uses of the \" string inside awk.

So, you probably want this:

awk -F'\t' '{print "\"<li>" $2 "(" $3 ")</li>\""}' OFS='","' datafile.csv
Source Link
QuartzCristal
  • 2.1k
  • 5
  • 25

Your issue seems to be with the \" you are using.

  1. Once you start a quoted string with" it goes to the next (unquoted) ". A \" inserted inside the quoted string will not terminate that qouted string but will be inserted "as is", i. e.: a double quote character.

  2. Inside a quoted string the $n values are not expanded.

$ echo "one two three" | awk '{print "$2,$3"}'
$2,$3

$ echo "one two three" | awk '{print "\"$2,$3\""}'
"$2,$3"

$ echo "one two three" | awk '{print "\"",$2,$3,"\""}'   # concatenated quotes
" two three "

$ echo "one two three" | awk '{print "\"" $2 $3 "\""}'   # only one string
"twothree"

$ echo "one two three" | awk '{print "\""$2,$3"\""}'     # two strings
"two three"

$ echo "one two three" | awk '{print "\""$2"\"","\""$3"\""}'  # Using OFS
"two" "three"

$ echo "one two three" | awk -vOFS="," '{print "\""$2"\"","\""$3"\""}' # Changing OFS
"two","three"

Those are some possible uses of the \" string inside awk.