Searching a set of lines in unix [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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 * and eeee, (count should not include cccc and dddd)
    For the above lines I'll get answer 4.


  • get the file name if dddd is present.










share|improve this 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 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














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 * and eeee, (count should not include cccc and dddd)
    For the above lines I'll get answer 4.


  • get the file name if dddd is present.










share|improve this 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 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












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 * and eeee, (count should not include cccc and dddd)
    For the above lines I'll get answer 4.


  • get the file name if dddd is present.










share|improve this question















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 * and eeee, (count should not include cccc and dddd)
    For the above lines I'll get answer 4.


  • get the file name if dddd is present.







text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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










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.






share|improve this answer



























    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





    share|improve this answer



























      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.






      share|improve this answer
























        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.






        share|improve this answer






















          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 3 at 4:31









          Beans

          11




          11






















              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





              share|improve this answer
























                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





                share|improve this answer






















                  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





                  share|improve this answer












                  #!/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






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 3 at 4:32









                  rhubarbdog

                  1012




                  1012












                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)