skip to Main Content

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 😀 so I hope this makes sense, isn’t a dumb question and that I formatted it all correctly!

2

Answers


  1. 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
    
    Login or Signup to reply.
    • 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search