The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep and display few lines before and after melanie_pfefer SUN Solaris 8 09-25-2008 08:05 AM
grep a word and display its column Orbix UNIX for Dummies Questions & Answers 1 12-24-2007 05:32 PM
How to display first 7 char of grep results? kthatch UNIX for Dummies Questions & Answers 8 04-04-2007 10:00 PM
using cat and grep to display missing records jxh461 UNIX for Dummies Questions & Answers 4 01-13-2007 06:56 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-24-2006 09:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-19-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy Grep and display

I have the following data:

A
1
2
3
A
4
5
6
A
7
8
9

I want to grep this data with A and 3 lines below it then display them in this format:
A 1 2 3
A 4 5 6
A 7 8 9

My grep comand is:

grep +3 "A" datafile

Can someone help me to have the data lay out as describe above?

Many thanks!
Reply With Quote
Forum Sponsor
  #2  
Old 06-19-2006
Registered User
 

Join Date: May 2006
Location: Vancouver, BC
Posts: 11
I am not sure that you understand the grep command because it seems as though you are trying to format data which is in a fixed order, rather than search for specific patterns of text - which is the main function of grep.

Please confirm this before I continue with some possibilities that may apply?
Reply With Quote
  #3  
Old 06-19-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy

I understand the grep. I just need help with the arrangement of the data.

My data:

A
1
2
3
A
4
5
6
A
7
8
9

Need to be:

A 1 2 3
A 4 5 6
A 7 8 9

Thanks!
Reply With Quote
  #4  
Old 06-19-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
nawk 'ORS=(FNR%4)?FS:"\n"' myFile.txt
Reply With Quote
  #5  
Old 06-19-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Thumbs up

This is working GREAT! Thank you much!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0