The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > Windows & DOS: Issues & Discussions
Google UNIX.COM


Windows & DOS: Issues & Discussions Questions involving Unix to Windows (Desktop or Server) go here. Any Windows/DOS questions should go here as well.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-09-2007 11:25 PM
Exporting text file data to csv l_jayakumar Shell Programming and Scripting 3 09-18-2005 08:27 PM
filter data deep.singh UNIX for Dummies Questions & Answers 3 08-14-2005 08:24 PM
How to extract data from a text file negixx Shell Programming and Scripting 1 07-19-2005 06:30 PM
getting data out from a text file skotapal Shell Programming and Scripting 7 09-14-2002 08:10 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8 (permalink)  
Old 04-14-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
awk '/^----*Table/{table=$0}
/^IP=/{ print table }' file
Do you really have a variable number of dashes before the "Table"?
Reply With Quote
Forum Sponsor
  #9 (permalink)  
Old 04-14-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,549
Code:
awk '$0 ~ v { printf "%s\n%s\n", x, $0 }
/^--/ { x = "" } { x = x ? x RS $0 : $0 }
' v="^IP=172.18.0.1$" file
Use nawk or /usr/xpg4/bin/awk on Solaris.

Perhaps I misread the question, if you need only the table names,
you should use the code era posted.
Reply With Quote
  #10 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
Thank you radoulov and era.

Radoulov solution very near that what I am looking for.

This script (radoulov) print out from tables only those rows which are before IP=x.x.x.x
After IP=x.x.x.x are couple rows more and I like to print out those too.
Reply With Quote
  #11 (permalink)  
Old 04-15-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,549
Code:
awk 'END { if (f) print x } $0 ~ v && f++
/^--/ { if (f) print x; x = f = 0 }
{ x = x ? x RS $0 : $0 }' v="^IP=172.18.0.1$" file
Reply With Quote
  #12 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
/usr/xpg4/bin/awk: syntax error Context is:
>>> END { if (f) print x } $0 ~ v && f++/---- <<<
Reply With Quote
  #13 (permalink)  
Old 04-15-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,549
Quote:
Originally Posted by Hone1975 View Post
/usr/xpg4/bin/awk: syntax error Context is:
>>> END { if (f) print x } $0 ~ v && f++/---- <<<
Copy/paste my code,
there's a newline after f++ ...

(why this thread is in Windows & DOS: Issues & Discussions?)
Reply With Quote
  #14 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
Quote:
Originally Posted by radoulov View Post
Copy/paste my code,
there's a newline after f++ ...

(why this thread is in Windows & DOS: Issues & Discussions?)
Why this thread: This case was very near of my needs and I am very new forum user and I didn't remenber to check is my case in the right place.

Sorry.

What do you mean new line? If I put your code to my Solaris shell window I get error message (If I copy and paste your code).
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:51 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 Global Fact Book

Content Relevant URLs by vBSEO 3.2.0