awk
syntax
FR & FNR
[!NOTE|label:references:]
tips
NR == FNR: first file
NR != FNR: all files except the first one
FILENAME
[!NOTE|label:references:]
output
[!NOTE]
[!TIP|label:original content]
or
or
[!NOTE|label:references:]
reverse words
[!NOTE]
NOTE:
revnot working since number will be reversed to different values
align
[!NOTE]
merge every 2 lines
[!NOTE|label:references:]
right/left alignment
alignment with fixed column
append space
[!NOTE]
and more
convert csv format
unique
removal
remove non-duplicated lines
or
show only non-duplicated lines
combination
[!NOTE|label:references:]
Using AWK to Process Input from Multiple Files
FNR == NR: read 1st file
FNR != NR: read 2nd file
[!NOTE] objective:
git status+git diff --stat
show matched values
find distrib name from
/etc/lsb-releasereturn
trueorfalseaccording to matches result
split
split with result
[!NOTE|label:real situation]
original string
filter via
:
last n columns
last 2 columns
second-to-last column ( --NF )
--NF )via
cut -f<n>-
trim
[!NOTE|label:references:]
calculate
length
longest line
[!NOTE] Longest line in a file
longest filename
print chars and length
or using
while
sum
[!NOTE|label:references:]
base on other column
[!NOTE]
sum $4 base on $2 and print original
sum before date
[!TIP|label:substr]
substrVS. original string:
sum $2 base on $1
sum lines by extension
summary mem for all users (ps aux)
ps aux)or
summary all in nth column
nth columnsum since nth line
sum for each column
[!NOTE|label:references:]
calculate word count in a file
or
or
maximize & minimize
field
multiple delimiters
[!NOTE]
-F"[..]"-F"(..)"[!TIP] the
\should be\\\in "(..)"simprude solution
-F'..'BEGIN{ FS=".." }
field separator variable
multiple separators
[!NOTE|label:multiple separators]
How to use a shell command to only show the first column and last column in a text file?
FS: Input field separator variableOFS: Output Field Separator Variable
example target : set both
:(colon) and (space/blank) as separators
FS/OFS
parser
csv
[!NOTE|label:references:]
cheatsheet
[!NOTE|label:references:]
sample code
[!NOTE|label:references:]
sample code:
Last updated
Was this helpful?