searching letter patterns within words
Hi guys,
I have a long long list of nouns with frequency, so two columns: alpha 45 beta 3 gamma 45 I need to find some particular patterns with the words, like for example "ph" in alpha, and copy the entire line (alpha 45). When I want to look for the entire word, I generally use awk '$1 == "alpha"{print $0}' infile.txt > outfile.txt but how should I procede in this case? Additionally, how to make the search case-insensitive? I thank you very much for any possible suggestion! Sincerely, Udiubu |
Code:
cat myfile | grep -i ph |
Cheers! I actually realized that grep could solve it already.
Well, I wanted to use awk, because in a second step I wanted to copy the second column only. Anyways, thanks a lot. Best, Emiliano |
Using awk you can set the IGNORECASE built-in variable to a non-zero value and try something like this (using a regular expression instead of string comparison):
Code:
awk 'BEGIN{IGNORECASE=1}/ph/{print $2}' file Code:
awk '/[Pp][Hh]/{print $2}' file |
Code:
cat myfile | grep -i ph | cut -d" " -f2 |
You do realise grep take as a filename as a param ie no 'cat' reqd ...
|
Yep ..
|
All times are GMT -5. The time now is 01:41 AM. |