1
I'm searching for one liner command (in best way) that can find if specific string/line is presented between other two lines. I search for it and I only found commad to get content between two lines, but how can i check if someting is present or not..
.....
1 a 2 b 3
4
5
.....
1 c 2 d 3
4
5
.....
1 e 2 f 3
5
.....
I found this:
sed -n '/^ 1 .* 2 .* 3$/,/^ 5$/p'
the result with this command cut the unwanted lines good for start (cut lines "...."), but still not know how to check if "4" is presented between :
1 a 2 b 3
4
5
1 c 2 d 3
4
5
1 e 2 f 3
5
The output should look like this:
"4" is missing after "1 e 2 f 3"
OR only (is even better):
"1 e 2 f 3"
Thanks! works for me, it is little complicate but is not problem :). One question: because I run script from my home dir and the files that have to check are on other dir, but they are a lot... it is possible to print the FILENAME here ?? Because now I't works but I don't know witch result in which file is :( – loken – 2018-03-24T10:34:13.723
How exactly are you processing this? I would recommend just
echo
ing the filename on a separate line. If you aren't sure about how to do this, feel free to paste your script and I'll give you a recommendation on where to put theecho
. – sneep – 2018-03-24T10:46:59.0871
grep -v -e '^$'
could be like this in sed/^$/d
(or/^$/!p
since-n
option is present). GNUsed has theF
command to print file name input1F
will print it as first line of output. – Paulo – 2018-03-24T13:56:37.257I tried using
d
, but that didn't seem to work on the holding buffer, and it also seemed to jump out of the block and start processing the next line. I'll incorporate the other suggestions though! Thanks a lot! – sneep – 2018-03-24T14:52:33.870Thanks sneep !!! working fine. Can you suggest me what other program I can use - awk maybe ? Can someone give AWK solution ? – loken – 2018-03-26T10:24:42.797
Cool! Once you're sure that the script does what you need, if you could accept my answer or at least vote it up, that would be great too. :) – sneep – 2018-03-26T10:39:47.910
Ah. Well I personally think perl would be the best tool for the job. – sneep – 2018-03-26T10:40:59.990