我需要从以下字符串中提取以下四个字符的匹配项:
站点
KPAE
KPSC
KPUW
KRNT
KSEA
KSFF
KSHN
KTIW
数据:
{"sids": ["24222 1", "452670 2", "PAE 3", "KPAE 5", "USW00024222 6"], "name": "EVERETT SNOHOMISH AP"},
{"sids": ["24163 1", "PSC 3", "KPSC 5", "USW00024163 6"], "name": "PASCO TRI CITIES AP"},
{"sids": ["94129 1", "PUW 3", "KPUW 5", "USW00094129 6"], "name": "PULLMAN MOSCOW RGNL AP"},
{"sids": ["94248 1", "RNT 3", "KRNT 5", "USW00094248 6"], "name": "RENTON MUNI AP"},
{"sids": ["24233 1", "457473 2", "SEA 3", "72793 4", "KSEA 5", "USW00024233 6", "SEA 7"], "name": "SEATTLE TACOMA INTL AP"},
{"sids": ["94176 1", "SFF 3", "KSFF 5", "USW00094176 6"], "name": "SPOKANE FELTS FLD"},
{"sids": ["94227 1", "457585 2", "SHN 3", "KSHN 5", "USW00094227 6", "SHN 7"], "name": "SHELTON SANDERSON FLD"},
{"sids": ["94274 1", "TIW 3", "KTIW 5", "USW00094274 6"], "name": "TACOMA NARROWS AP"},
我试图从字符串中提取这些匹配但是,它们的位置可以从字符串更改为字符串...
尝试过的代码:
awk -F',' '{print $5}'
答案 0 :(得分:2)
使用grep -oP
:
grep -Po '"\K[A-Z]{4}\b' file
KPAE
KPSC
KPUW
KRNT
KSEA
KSFF
KSHN
KTIW