I want to search in a long sentence (more than 1024 letters).
I have one text file (test.txt) which has one long sentence, like this:
afdafglwqgkjrldjl;ewqje;'k;g;je;;;fdsgalsdkf;akslg;safdas.....dasfsd
Now I want to check which line contains the word saf. This command just shows the whole sentence:
less test.txt | grep saf
Is it possible to get a part of the sentence or should I use a command other than grep?
grep -o 'saf' text.text? – Cyrus Oct 19 '18 at 14:54grep -o '.\{0,3\}saf.\{0,3\}' text.text– this will include up to three characters before and up to three characters after. But if there is a secondsafand it begins within these "three characters after" then it won't be matched separately. – Kamil Maciorowski Oct 19 '18 at 15:48