LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 12:43 PM   #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, 07:54 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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, 08:07 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
ditto ... Please give example
 
Old 06-26-2008, 12:19 AM   #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-26-2008, 12:42 AM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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, 01:09 AM   #6
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,517

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
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, 07: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, 09: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:55 PM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 09:22 AM
script to check the last line in a file is blank line or not naveensankineni Programming 10 03-02-2008 12:13 AM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 02:43 PM


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

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration