I have this:
if [[ $1 = "-c" ]] && [[ $2 =~ ^[a-z A-Z]+$ ]]
then
awk -v var="$2" '{print $2}' something.txt
fi
What I want is with a comand like -c abc
to show the lines in something.txt that include abc
.
Use grep:
Also note that using The shell requires the In The For just printing all lines of a file that match a given pattern, use |
|||||
|
just as a disclaimer, awk isn't the right tool for this job — i'm assuming your actual use case is more complex and justified, so thanks for distilling it! This specific issuse looks like it comes down to two things, variable "expansion" and passing args from bash to awk. awk variables and
|
|
|||
|
I don't think they want the
index , but the whole line. But I agree that grep is much simpler.
– Sparhawk
2 days ago
|
||
|
that's correct @Sparhawk. That won't print the index, it will print the whole line; playing to some of awk's shortcut friendliness — It's about as close as you'll get to a substring matcher in awk
– user3276552
2 days ago
|
||
|
grep
? That's the tool for the job. Simple is usually better. – Wildcard 2 days ago