2
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 – 2018-10-19T14:54:15.037THanks! It shows the matched point. however is it possible to show the a few letters before and after of matches??? – whitebear – 2018-10-19T14:56:49.900
grep -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 secondsaf
and it begins within these "three characters after" then it won't be matched separately. – Kamil Maciorowski – 2018-10-19T15:48:16.740@KamilMaciorowski It's perfect what I want. it works prety well – whitebear – 2018-10-23T21:44:57.083