Use AWK to get last 2 columns of cookie files below comments

2

I currently have a cookie.txt file that looks like so.

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file!  Do not edit.

.youtube.com    TRUE    /   FALSE   1547252593  GPS 1
.youtube.com    TRUE    /   FALSE   1552434792  PREF    f1=50000000&hl=en
.youtube.com    TRUE    /   FALSE   1562802793  VISITOR_INFO1_LIVE  inJgRBNv-3I
.youtube.com    TRUE    /   FALSE   0   YSC 9U9ILYfJDyA
.youtube.com    TRUE    /   FALSE   0   s_gl    1d69aac621b2f9c0a25dade722d6e24bcwIAAABVUw==

I'm trying to use awk to read the cookie.txt file and from each of the .youtube.com lines get the last 2 fields, ie GPS 1, PREF f1=50000000&hl=en, etc.

Can this be done with awk ignoring the base 3 comment lines?

nadermx

Posted 2019-01-16T20:14:50.880

Reputation: 387

Answers

2

You can use this awk expression:

awk 'NR>4 { print $6,$7 }' cookie.txt
  • NR>4 skips the first 4 lines
  • print $6,$7 prints the sixth and seventh field delimited by the OFS value

Its Output is:

GPS 1
PREF f1=50000000&hl=en
VISITOR_INFO1_LIVE inJgRBNv-3I
YSC 9U9ILYfJDyA
s_gl 1d69aac621b2f9c0a25dade722d6e24bcwIAAABVUw==

zx485

Posted 2019-01-16T20:14:50.880

Reputation: 2 008

Space is defauls separator, so its not need to be defined explicitely – Romeo Ninov – 2019-01-16T20:32:19.443

1@Romeo Ninov: Thanks. I simplified my answer. – zx485 – 2019-01-16T20:33:26.210

1

Something like can do the work:

awk '$1!~"^#"  {if (NF!=0) print $(NF-1),$NF}' cookie.txt

Romeo Ninov

Posted 2019-01-16T20:14:50.880

Reputation: 2 062