LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grab the line below a blank line and the line above the next blank line awk or perl? (https://www.linuxquestions.org/questions/linux-general-1/grab-the-line-below-a-blank-line-and-the-line-above-the-next-blank-line-awk-or-perl-651596/)

Pantomime 06-25-2008 11:43 AM

grab the line below a blank line and the line above the next blank line awk or perl?
 
Hello,

I am trying to grab the full line below a blank line and the full line above the next blank line, group them together and throw a blank line inbetween them and the next entry like that in the output.

There might also be an easier way, I am trying to get the folder size and the last access time of that folder to make an audit.

Any help would be appreciated. Thanks!

Mr. C. 06-25-2008 06:54 PM

How about showing us the real command output you are trying to parse, and how you want it to look. I'm pretty confused with your description.

chrism01 06-25-2008 07:07 PM

ditto ... Please give example

iAlta 06-25-2008 11:19 PM

as I understand it OP wants:
Code:

{BLANK}
qwerty
rtuygfvbfgh
jhgfghjrtyg
12345
{BLANK}

turned into:
Code:

qwerty
{BLANK}
12345


Mr. C. 06-25-2008 11:42 PM

That may very well be, but the issue is one of forcing a method of implementation based upon the OPs current perception of how to obtain an answer to a given problem.

A better method would be to describe the goal more precisely (eg. "how do I get total folder size and last access time of a file in a folder?") rather than focusing on the implementation ("how to I solve some problem using some tool I'm not sure is the right tool").

If I am correct in what the user is asking, this is not the best or easiest approach. But I'll wait the OP to clarify.

allend 06-26-2008 12:09 AM

Quote:

There might also be an easier way, I am trying to get the folder size and the last access time of that folder to make an audit.
I think the OP wants 'du --time'.
This will give the directory size and time of last modification of a file in a directory.

Pantomime 06-26-2008 06:53 AM

I finagled a way to get the output I desired. It wasn't the most elegant approach. I wanted

{BLANK}
qwerty
rtuygfvbfgh
jhgfghjrtyg
12345
{BLANK}
67890
44444
88888
{blank}

turned into

{blank}
qwerty
12345
{blank}
67890
88888
{blank}

basicly just take the first and last lines in a block of text and group them together.

beadyallen 06-26-2008 08:13 AM

Code:

cat file.txt | grep -C1 '^$' | grep -v '\-\-'
There may be a way to stop grep printing '--' between matched contexts, but I couldn't find it, hence the second grep.


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