Juan Jor Orellana Juan Jor Orellana - 13 days ago 5
Linux Question

Bash equivalent for SQL "1.%"

I'm aware than whenever I want to filter columns or... basically anything in a SQL query, i can use something like

Select * from table1 where name1 like "Mr.%"


This part

like "Mr.%"


Should grab any row in which the var name1 starts with "Mr." no matter what else is after it.

My question: Is there an equivalent for it in bash? anything to go with grep, maybe?

Answer

You can do it with grep easily:

For a file:

grep '^Mr\.' myfile.txt

For command output:

my-command-with-output | grep '^Mr\.'

EDIT: Adding an example with your example text file string:

grep '^1' myfile.txt

The example above will find any lines with starting with the number 1.