0

I have in the input file a column with the following format

H6
H7
O4
C4
H8
H9
O5
C5
H10
H11

I want the output to have the following format

"a H6"
"a H7"
"a O4"
"a C4"
"a H8"
"a H9"
"a O5"
"a C5"
"a H10"
"a H11"

I tried so far awk '{print "a "$1""}' filein > fileout

but the output was not the desired as I got a column with missing the " ".

1

4 Answers 4

2

You must escape the double quotes in awk. Something like will do the work

awk '{print "\"a "$1 "\" "}' filein > fileout
0
1

And use printf instead of print in your Awk command to output into a single line.

awk '{printf "\"a "$1"\" "}' inputFile > outputFile
0
0

I would just use sed for this:

sed 's/^/"a /; s/$/"/' infile > outfile

This produces:

$ sed 's/^/"a /; s/$/"/' infile 
"a H6"
"a H7"
"a O4"
"a C4"
"a H8"
"a H9"
"a O5"
"a C5"
"a H10"
"a H11"
0
0
sed 's/.*/"a &"/' data

& is the whole matched text.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.