Home > Enterprise >  How do set the delimiter to " when using AWK in linux
How do set the delimiter to " when using AWK in linux

Time:10-06

So I have a text file with

"sam", "james", "john"
"luke", "polly", "jack"

I am looking for an awk command that will isolate each name. I seem to be running into the issue that awk does not like me setting " as the delimiter

I would like it to look like

sam
luke

if I were to try and print field 0

I have tried these commands

awk -F""" '{print $0}' test.txt
awk -F"\"" '{print $0}' test.txt
awk -F'"' '{print $0}' test.txt
awk -F'\"' '{print $0}' test.txt
awk -F" '{print $0}' test.txt

None of those seems to have worked. This is my first time asking a question on here. Also started learning to code about 5 weeks ago as well :D so I hope this makes sense, isn't a dumb question and that I formatted it all correctly!

CodePudding user response:

With your shown samples please try following. Basically you need to print the correct field number here to get your expected output. That field number would be 2nd field.

awk -F'"' '{print $2}' Input_file

CodePudding user response:

  • extracting all names into a linear list :
gawk '!_<NR' RS='[^[:alpha:]] '
sam
james
john
luke
polly
jack
  • extracting just 1st column :
mawk NF=NF FS='^\"|\",. $' OFS= 
sam
luke
  • Related