LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-25-2008, 11:43 AM   #1
Pantomime
LQ Newbie
 
Registered: Jun 2008
Posts: 2

Rep: Reputation: 0
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!
 
Old 06-25-2008, 06:54 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
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.
 
Old 06-25-2008, 07:07 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
ditto ... Please give example
 
Old 06-25-2008, 11:19 PM   #4
iAlta
Member
 
Registered: Oct 2005
Distribution: Ubuntu 7.10, OpenSUSE 10.3, Linux Mint, Arch
Posts: 92

Rep: Reputation: 15
as I understand it OP wants:
Code:
{BLANK}
qwerty
rtuygfvbfgh
jhgfghjrtyg
12345
{BLANK}
turned into:
Code:
qwerty
{BLANK}
12345
 
Old 06-25-2008, 11:42 PM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
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.
 
Old 06-26-2008, 12:09 AM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,372

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
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.
 
Old 06-26-2008, 06:53 AM   #7
Pantomime
LQ Newbie
 
Registered: Jun 2008
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
Old 06-26-2008, 08:13 AM   #8
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PERL:how to find a blank line in a file--regular expression littletransformer Programming 4 03-27-2008 06:55 PM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
script to check the last line in a file is blank line or not naveensankineni Programming 10 03-01-2008 11:13 PM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration