The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 04:38 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 05:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
Need help on getting value from a file

I have a file which contains the data like below.It conatins more data than i posted here.

BEGIN DSJOB
Identifier "TestPart"
DateModified "2008-10-08"
TimeModified "00.36.32"
Identifier "ROOT"
DateModified "1899-12-30"
TimeModified "00.00.01"
OLEType "CJobDefn"
Readonly "0"
Name "Test"
NextID "1"
Container "V0"
JobVersion "50.0.0"
ControlAfterSubr "0"
MetaBag "CMetaProperty"
BEGIN DSSUBRECORD
BEGIN DSJOB
Identifier "GetFile"
DateModified "2008-10-05"
Identifier "ROOT"
DateModified "1899-12-30"
TimeModified "00.00.01"
OLEType "CJobDefn"
Readonly "0"
Name "Test"
NextID "1"
Container "V0"
JobVersion "50.0.0"
ControlAfterSubr "0"
MetaBag "CMetaProperty"
BEGIN DSSUBRECORD
BEGIN DSJOB
Identifier "TrimFields"
DateModified "2008-10-05"
Identifier "ROOT"
DateModified "1899-12-30"
TimeModified "00.00.01"
OLEType "CJobDefn"
Readonly "0"
Name "Test"
NextID "1"
Container "V0"
JobVersion "50.0.0"
ControlAfterSubr "0"
MetaBag "CMetaProperty"
BEGIN DSSUBRECORD
BEGIN DSJOB
Identifier "ConvertDate"
DateModified "2008-10-05"
Identifier "ROOT"
DateModified "1899-12-30"
TimeModified "00.00.01"
OLEType "CJobDefn"
Readonly "0"
Name "Test"
NextID "1"
Container "V0"
JobVersion "50.0.0"
ControlAfterSubr "0"
MetaBag "CMetaProperty"
BEGIN DSSUBRECORD
BEGIN DSJOB
Identifier "LoadTable"
DateModified "2008-10-05"
Identifier "ROOT"
DateModified "1899-12-30"
TimeModified "00.00.01"
OLEType "CJobDefn"
Readonly "0"
Name "Test"
NextID "1"
Container "V0"
JobVersion "50.0.0"
ControlAfterSubr "0"
MetaBag "CMetaProperty"
BEGIN DSSUBRECORD
BEGIN DSJOB
Identifier "Test"
DateModified "2008-10-05"



In the above text I need to grep for "BEGIN DSJOB" and when ever i find this text i need the line after this text.

Out put :

Identifier "TestPart"
Identifier "GetFile"
Identifier "TrimFields"
Identifier "ConvertDate"
Identifier "LoadTable"
Identifier "Test"

Please give me some suggestion how can i acheive this.

Thanks
  #2 (permalink)  
Old 10-08-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,930
Code:
awk '{ if ( match($0, "^BEGIN DSJOB") ) { getline; print } }' filename
  #3 (permalink)  
Old 10-13-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
I have a question like if i want 3rd line from that record how can i get it.

Thanks
  #4 (permalink)  
Old 10-14-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,930
Quote:
Originally Posted by ukatru View Post
I have a question like if i want 3rd line from that record how can i get it.

Thanks
Sorry, your question is not clear.

Did you mean from the file

Code:
awk ' NR == 3 { print }' filename
or
from the output ?
  #5 (permalink)  
Old 10-14-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
From the same file I need to grep for "BEGIN DSJOB" and get the second line from that line

Ex output:

DateModified "2008-10-08"
DateModified "2008-10-05"
....

Thanks
  #6 (permalink)  
Old 10-14-2008
MrC MrC is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 51
You can do this simply enough with grep:

$ grep -A 2 '^BEGIN DSJOB' datafile | grep DateMod
  #7 (permalink)  
Old 10-15-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
you can simply do this..
Code:
awk 'c-->0;/BEGIN DSJOB/{c=2}' filename
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0