Ads

Check out value in brief website for more up-to-date content.

how to word search in a file?

in terminal

!cat /home/manjo/Work/my_file.txt

in bash script

%%bash

grep -o "Linux" /home/manjo/Work/my_file.txt

in Python script / program

%%python3

from pathlib import Path

from re import findall

file = '/home/manjo/Work/my_file.txt'

fr = Path(file).read_text()

print(*findall('Linux', fr), sep = '\n')

If you want to get new posts, make sure to subscribe to Value In Brief by Email.