Searching a set of lines in unix [closed]

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a abc.log file having the below details
Aaaa
Bbbb
Cccc filename
Dddd
Dddd
Dddd
Eeee
Ffff
I'm trying to write a unix script to
count the no of same lines from
cccc *andeeee, (count should not includeccccanddddd)
For the above lines I'll get answer 4.get the file name if dddd is present.
text-processing
closed as unclear what you're asking by Stephen Harris, G-Man, Kusalananda, Sparhawk, sam Dec 3 at 16:17
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
I have a abc.log file having the below details
Aaaa
Bbbb
Cccc filename
Dddd
Dddd
Dddd
Eeee
Ffff
I'm trying to write a unix script to
count the no of same lines from
cccc *andeeee, (count should not includeccccanddddd)
For the above lines I'll get answer 4.get the file name if dddd is present.
text-processing
closed as unclear what you're asking by Stephen Harris, G-Man, Kusalananda, Sparhawk, sam Dec 3 at 16:17
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
3
your question is very unclear. do you mind editing it. you count lines withwc -l
– rhubarbdog
Dec 3 at 3:54
I wanna search two patterns. If both patterns is present in the log file , I wanted to count the intermediate lines.
– Narmatha
Dec 3 at 3:59
So… from the question, do you want a case-insensitive search? And if you don't includedddd, then how do you get "4" as the answer?
– Sparhawk
Dec 3 at 7:46
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a abc.log file having the below details
Aaaa
Bbbb
Cccc filename
Dddd
Dddd
Dddd
Eeee
Ffff
I'm trying to write a unix script to
count the no of same lines from
cccc *andeeee, (count should not includeccccanddddd)
For the above lines I'll get answer 4.get the file name if dddd is present.
text-processing
I have a abc.log file having the below details
Aaaa
Bbbb
Cccc filename
Dddd
Dddd
Dddd
Eeee
Ffff
I'm trying to write a unix script to
count the no of same lines from
cccc *andeeee, (count should not includeccccanddddd)
For the above lines I'll get answer 4.get the file name if dddd is present.
text-processing
text-processing
edited Dec 3 at 8:18
Rui F Ribeiro
38.5k1479128
38.5k1479128
asked Dec 3 at 3:49
Narmatha
12
12
closed as unclear what you're asking by Stephen Harris, G-Man, Kusalananda, Sparhawk, sam Dec 3 at 16:17
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Stephen Harris, G-Man, Kusalananda, Sparhawk, sam Dec 3 at 16:17
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
3
your question is very unclear. do you mind editing it. you count lines withwc -l
– rhubarbdog
Dec 3 at 3:54
I wanna search two patterns. If both patterns is present in the log file , I wanted to count the intermediate lines.
– Narmatha
Dec 3 at 3:59
So… from the question, do you want a case-insensitive search? And if you don't includedddd, then how do you get "4" as the answer?
– Sparhawk
Dec 3 at 7:46
add a comment |
3
your question is very unclear. do you mind editing it. you count lines withwc -l
– rhubarbdog
Dec 3 at 3:54
I wanna search two patterns. If both patterns is present in the log file , I wanted to count the intermediate lines.
– Narmatha
Dec 3 at 3:59
So… from the question, do you want a case-insensitive search? And if you don't includedddd, then how do you get "4" as the answer?
– Sparhawk
Dec 3 at 7:46
3
3
your question is very unclear. do you mind editing it. you count lines with
wc -l– rhubarbdog
Dec 3 at 3:54
your question is very unclear. do you mind editing it. you count lines with
wc -l– rhubarbdog
Dec 3 at 3:54
I wanna search two patterns. If both patterns is present in the log file , I wanted to count the intermediate lines.
– Narmatha
Dec 3 at 3:59
I wanna search two patterns. If both patterns is present in the log file , I wanted to count the intermediate lines.
– Narmatha
Dec 3 at 3:59
So… from the question, do you want a case-insensitive search? And if you don't include
dddd, then how do you get "4" as the answer?– Sparhawk
Dec 3 at 7:46
So… from the question, do you want a case-insensitive search? And if you don't include
dddd, then how do you get "4" as the answer?– Sparhawk
Dec 3 at 7:46
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I haven't got enough reputation to add a comment so I'm just going to create an answer.
You could use something like the following:
cat filename | sort | uniq -c
sort is used to merge similar lines and uniq gives you a count of each occurrence of a line.
add a comment |
up vote
0
down vote
#!/bin/bash
# usage ./line_count.sh <filename>
hd=`grep cccc -i -n $1 | awk -F: 'print $1'` || exit 1
hd=`expr $hd '+' 1`
opt='-'$hd
head $opt $1 | tail -1 | grep -i dddd >/dev/null || exit 1
lines=`wc -l $1 | awk 'print $1'`
expr $lines '-' $hd
exit 0
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I haven't got enough reputation to add a comment so I'm just going to create an answer.
You could use something like the following:
cat filename | sort | uniq -c
sort is used to merge similar lines and uniq gives you a count of each occurrence of a line.
add a comment |
up vote
0
down vote
I haven't got enough reputation to add a comment so I'm just going to create an answer.
You could use something like the following:
cat filename | sort | uniq -c
sort is used to merge similar lines and uniq gives you a count of each occurrence of a line.
add a comment |
up vote
0
down vote
up vote
0
down vote
I haven't got enough reputation to add a comment so I'm just going to create an answer.
You could use something like the following:
cat filename | sort | uniq -c
sort is used to merge similar lines and uniq gives you a count of each occurrence of a line.
I haven't got enough reputation to add a comment so I'm just going to create an answer.
You could use something like the following:
cat filename | sort | uniq -c
sort is used to merge similar lines and uniq gives you a count of each occurrence of a line.
answered Dec 3 at 4:31
Beans
11
11
add a comment |
add a comment |
up vote
0
down vote
#!/bin/bash
# usage ./line_count.sh <filename>
hd=`grep cccc -i -n $1 | awk -F: 'print $1'` || exit 1
hd=`expr $hd '+' 1`
opt='-'$hd
head $opt $1 | tail -1 | grep -i dddd >/dev/null || exit 1
lines=`wc -l $1 | awk 'print $1'`
expr $lines '-' $hd
exit 0
add a comment |
up vote
0
down vote
#!/bin/bash
# usage ./line_count.sh <filename>
hd=`grep cccc -i -n $1 | awk -F: 'print $1'` || exit 1
hd=`expr $hd '+' 1`
opt='-'$hd
head $opt $1 | tail -1 | grep -i dddd >/dev/null || exit 1
lines=`wc -l $1 | awk 'print $1'`
expr $lines '-' $hd
exit 0
add a comment |
up vote
0
down vote
up vote
0
down vote
#!/bin/bash
# usage ./line_count.sh <filename>
hd=`grep cccc -i -n $1 | awk -F: 'print $1'` || exit 1
hd=`expr $hd '+' 1`
opt='-'$hd
head $opt $1 | tail -1 | grep -i dddd >/dev/null || exit 1
lines=`wc -l $1 | awk 'print $1'`
expr $lines '-' $hd
exit 0
#!/bin/bash
# usage ./line_count.sh <filename>
hd=`grep cccc -i -n $1 | awk -F: 'print $1'` || exit 1
hd=`expr $hd '+' 1`
opt='-'$hd
head $opt $1 | tail -1 | grep -i dddd >/dev/null || exit 1
lines=`wc -l $1 | awk 'print $1'`
expr $lines '-' $hd
exit 0
answered Dec 3 at 4:32
rhubarbdog
1012
1012
add a comment |
add a comment |
3
your question is very unclear. do you mind editing it. you count lines with
wc -l– rhubarbdog
Dec 3 at 3:54
I wanna search two patterns. If both patterns is present in the log file , I wanted to count the intermediate lines.
– Narmatha
Dec 3 at 3:59
So… from the question, do you want a case-insensitive search? And if you don't include
dddd, then how do you get "4" as the answer?– Sparhawk
Dec 3 at 7:46