0

I'm using Amazon Linux, bash shell. I have this statement, which extracts and prints the second row from a file with comma-delimited data ...

awk -F',' 'select * FROM {print $2}' myfile.csv

I would liek to print out something a little more elaborate, specifically, getting my printed column into an SQL statement, so I tried this

 awk -F',' 'select * FROM user where id = {print $2}' myfile.csv

but the above prints out nothing. What am I doing wrong? Hwo can I extract my ID within other text (whcih in this case happens to be an SQL statement)?

0

You need to embed the SQL into the print statement, thusly:

awk -F, '{print "SELECT * from user where id = "$2";"}' /path/to/input.csv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.