The UNIX and Linux Forums  

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
counting the occurence of particular characters Audra UNIX for Dummies Questions & Answers 2 03-28-2008 10:01 AM
First occurence from grep namishtiwari UNIX for Dummies Questions & Answers 10 08-23-2007 09:44 AM
Extracting the last occurence Raynon Shell Programming and Scripting 9 05-03-2007 11:47 AM
grep the last occurence apalex UNIX for Dummies Questions & Answers 3 04-18-2002 07:03 PM
grep for certain occurence app4dxh UNIX for Dummies Questions & Answers 2 09-14-2001 04:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2006
kkm_job kkm_job is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
First Occurence

Hi,
This is the format of the file that i have
StartDate:10/01/06
EndDate :10/02/06

Cno Ccode
1 10
2 11


StartDate:10/03/06
EndDate :10/04/06

Cno Ccode
2 13
4 12


StartDate:10/01/06
EndDate :10/02/06

Cno Ccode
3 10
2 15




I need the first occurence of startdate and end date in a seperate file...
So the new file should have a row with values of
10/01/06,10/02/06


Can some help me writing the script


Thanks
Kiran
  #2 (permalink)  
Old 10-30-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk -F: '/StartDate/{dt1=$2;getline;print dt1","$2;exit}' file > dtfile
  #3 (permalink)  
Old 10-30-2006
nilesrex nilesrex is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 43
can you specify what exactly shld go in o/p file as ur question is not very clear
  #4 (permalink)  
Old 10-30-2006
kkm_job kkm_job is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
This is the O/p that should i see...
10/01/06,10/02/06
  #5 (permalink)  
Old 10-30-2006
nilesrex nilesrex is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 43
hope this helps

$ awk -F: '{ print $2 }' inputdata.txt | sed 'N;s/\n/ /'
10/01/06 10/02/06



10/03/06 10/04/06



10/01/06 10/02/06
  #6 (permalink)  
Old 10-30-2006
nilesrex nilesrex is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 43
awk -F: '{ print $2 "," }' inputdata.txt | sed -e 'N;s/\n/ /' | sed 's/,$//' | sed 's/^,//'

this one gives what you want but not good to have so many piped o/p's
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 10:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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