2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-12 19:10:26 +00:00

Add: awk paragraph search, separated output

This commit is contained in:
Igor Chubin 2022-08-29 09:32:32 +02:00
parent a26a0ee062
commit adfdf75cb7

View File

@ -47,8 +47,13 @@ awk -v RS='' '
printf '1 2 3' | awk 'BEGIN {OFS=":"}; {print $1,$2,$3}'
# Search paragraph for the given REGEX match.
# Paragraphs will be collapsed together.
awk -v RS='' '/42B/' file
# Search paragraph for the given REGEX match.
# Paragraphs will be separated with a new line.
awk -v RS= ORS='\n\n' '/42B/' file
# Display only first field in text taken from STDIN.
echo 'Field_1 Field_2 Field_3' | awk '{print $1}'
# Note that in this case, you're far better off using cut(1).