LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Extract info and find/count strings from blocks inside text file (https://www.linuxquestions.org/questions/programming-9/extract-info-and-find-count-strings-from-blocks-inside-text-file-4175532019/)

Alkass 01-24-2015 11:15 AM

Extract info and find/count strings from blocks inside text file
 
Hello

I have a text file which has blocks like
Code:

dir1/dir2/dir3/name_run_number1:
line1_run_number1_part1
line2_run_number1_part2
line3_run_number1_part3...

Each block is separated with a blank line and there is the ":" in the "header" of each one while each block carries the same "number1" after "run_" suffix
What I want to do is for each block, extract the "number1" as shown in the first line and then for the lines below count from 1-20 and give a message if a "partX" line is missing. Any bash or python would be fine

Thanks

danielbmartin 01-24-2015 11:23 AM

Help us to help you. You gave a sample input file (that's good) and some words (also good). Construct a sample output file which corresponds to your sample input and post it here. With "Before and After" examples we can better understand your needs and also judge if our proposed solution fills those needs.

Daniel B. Martin

Alkass 01-24-2015 11:34 AM

Hi

So, I would like to get an output like


"For number1 there are X entries in the corresponding block and partY is missing"

or in case all "20" parts are in place something like "for number1 all ok"

danielbmartin 01-24-2015 11:40 AM

Quote:

Originally Posted by Alkass (Post 5306099)
Hi

So, I would like to get an output like


"For number1 there are X entries in the corresponding block and partY is missing"

or in case all "20" parts are in place something like "for number1 all ok"

That's a description but is not a sample output file. Something more specific is needed.

Daniel B. Martin

Alkass 01-24-2015 11:47 AM

Well, if I had something more specific, then I could write the code my self wouldnt I ? I am new to all these, so if you can provide any code example would be great...

danielbmartin 01-24-2015 12:24 PM

Quote:

Originally Posted by Alkass (Post 5306102)
Well, if I had something more specific, then I could write the code my self wouldnt I ? I am new to all these, so if you can provide any code example would be great...

You are unwilling or unable to provide the requested sample. Therefore I bow out of this thread. Maybe someone else will step in to respond.

Daniel B. Martin

TB0ne 01-24-2015 12:26 PM

Quote:

Originally Posted by Alkass (Post 5306102)
Well, if I had something more specific, then I could write the code my self wouldnt I ? I am new to all these, so if you can provide any code example would be great...

I hate to tell you, but if you want this program then you are going to HAVE TO write it yourself. We will be happy to HELP you, but we aren't going to write your scripts for you. Read both the LQ Rules and the "Question Guidelines" link in my posting signature.

Again, as danielbmartin asked, provide at least a sample of what you want the output to look like. Write it manually if need be, and you will also have to provide us what YOU have written/tried on your own, and tell us where you're stuck. There are thousands of very easily found bash scripting tutorials you can find with a brief Google search...there is one on my posting signature, and the ones on TLDP are excellent, and all have samples.
http://www.tldp.org/
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

EDIT: Sorry, you are not "new to all these". You have been here for FIVE YEARS now, and have asked similar questions several times in the past, such as these from years ago:
http://www.linuxquestions.org/questi...ks-4175439457/
http://www.linuxquestions.org/questi...iteria-859135/

Show effort of your own, and don't ask people to do things for you. You will *NEVER* learn how to do anything if you keep asking others to do it for you.


All times are GMT -5. The time now is 03:22 AM.