How do I extract a record from address.txt that is separated by line breaks to four records and contains the string Pass?
If you enter the following command, you will see all output.
cat address.txt |awk'BEGIN {RS="";FS="\n"}$2=="Pass"'
address.txt
Yuichi Higashikawa
passing
080-1111-1111
〒111-1111
1-1-1 A-cho, XX-ku, XX-ken
ABC Building 1001
Yuji Nishimura
failure
080-2222-2222
〒222-2222
2-22 B-cho, XX prefecture, XX prefecture
Yuzo Namsan Mountain
passing
080-3333-3333
〒333-3333
3-3-3 C-cho, XX prefecture, XX prefecture
XYZ Heights Room 3
Yuzo Kitaoka
failure
080-4444-4444
〒444-4444
4-4-4 D-cho, XX-ku, XX-ken
RS
(Record Separator) should be two new lines (empty lines) and FS
(Field Separator) should be new lines. You can specify ORS
as you like.
awk-F'\n'-vRS='\n\n'-vORS='\n'$2=="Pass"'address.txt
Run Results
Yuichi Higashikawa
passing
080-1111-1111
〒111-1111
1-1-1 A-cho, XX-ku, XX-ken
ABC Building 1001
Yuzo Namsan Mountain
passing
080-3333-3333
〒333-3333
3-3-3 C-cho, XX prefecture, XX prefecture
XYZ Heights Room 3
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.