I have a list in a file named Target_id_convert.txt
70S ribosome
ALK tyrosine kinase receptor
ATP
ATP synthase
Desired output
('70S ribosome','ALK tyrosine kinase receptor','ATP','ATP synthase')
I have written this code
sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/" Target_id_convert.txt > Target_id_convert1.txt
tr '\n' ',' < Target_id_convert1.txt > Target_id_convert_output.txt
I then have to manually edit the file and add () in the Target_id_convert_output.txt file, Kindly let me know how to do it efficiently and all in one go, as It is all supposed to be automated.
This awk one-liner should do what you want:
awk -v q="'" '{$0=q $0 q;printf "%s%s", (NR==1?"(":","),$0}END{print ")"}' file
I declared a var q to have single quote ('), to avoid many escaping.
Assuming your records are double new-line separated, I would go with a sed/awk combo:
<file sed "/[^[:blank:]]/ s/.*/'&'/g" |
awk '{ $1=$1; print "(" $0 ")" }' RS= FS='\n' OFS=,
If the input is:
70S ribosome
ALK tyrosine kinase receptor
ATP
ATP synthase
70S ribosome
ALK tyrosine kinase receptor
ATP
ATP synthase
Output is:
('70S ribosome','ALK tyrosine kinase receptor','ATP','ATP synthase')
('70S ribosome','ALK tyrosine kinase receptor','ATP','ATP synthase')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With