Results 1 to 4 of 4
I have a 94 page long text file spaced with an extra blank line between records. The records consist of words of text separated by spaces. I need to pull ...
- 11-16-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 2
Bash text processing
I have a 94 page long text file spaced with an extra blank line between records. The records consist of words of text separated by spaces. I need to pull records one at a time 1 per day and the only field delimiter I have to use is an extra blank line. I can write bash scripts but I have no idea how to process the records using the field delimiter that I have to work with. I've looked into regular expressions but am unsure what command to use and the exact structure of the regular expression that I would need. If use a 'for' loop with 'cut' I cannot use a multiple character field delimiter (there are spaces between the words in the records). And I can't use various other commands because of this so I am looking to sed and awk but have no knowledge of how to use a regular expression to accomplish this.
Thanks.
- 11-16-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Can you give an example of the file and the output that you want?
Regards
- 11-16-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 2
The structure of the file is like this:
This is the first record just a bunch of plain old words.
The second record may be similar to this going on for I dont know how long. But I am not allowed to alter the file I only need to peel or cat records out of it and mail them to a list of people.
This is the third record just a bunch of plain old words.
so my desired output would be this:
This is the first redcord just a bunch of plain old words.
Then on the second day.
The second record may be similar to this going on for I dont know how long. But I am not allowed to alter the file I only need to peel or cat records out of it and mail them to a list of people.
- 11-16-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try this:
RegardsCode:awk 'BEGIN{cnt=1}{if(NR%2==0){cnt++;printf("\nThis is day %d\n\n", cnt)} else {print}}' file


Reply With Quote
