Extract lines from files with names begining with given letter
awk '$2 ~ /^L/' file
Tells awk
to test the second field $2
using the regex ~
expression ^L
and print the matching lines.
The regex matches the second field ($2
) when it starts ^
with L
Building on @bu5hman's answer: With awk, you can easily pass the letter as a parameter:
awk -v letter="L" 'substr($2, 1, 1) == letter' file
# or with a constructed regex
awk -v letter="L" '$2 ~ "^" letter' file
That seems to be duplicated, but anyway, if it was understood, one may do it as follows:
First, save the list in a some nameslist.txt
file, then:
sed -rn '/^[^\s]+\s+[F]/p' list.txt > result.txt
, which should return following output in result.txt
file:
60 FREDDIE 1201 +4
61 FINLAY 1200 -2