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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
split string using separetor rinku Shell Programming and Scripting 10 06-16-2009 02:01 PM
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
KSH split string into variables drd_2b Shell Programming and Scripting 5 04-23-2006 07:07 PM
split string help senthilk615 Shell Programming and Scripting 4 03-27-2006 06:43 PM
split a string gazingdown Shell Programming and Scripting 3 02-09-2006 05:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-04-2002
jpl35 jpl35 is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 3
Question split a file at a specified string

to find log files modification, i want to select all the lines of a file behind a string (found by grep ?).
  #2 (permalink)  
Old 07-04-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
To select all lines from beginning of the file up to but not including a specific line:
Code:
awk '{if (match($0,"string")) exit; print}' myfile
If you want all lines up to and including the specific line:
Code:
awk '{print; if (match($0,"string")) exit}' myfile
Identification of the termination line is being done by looking for "string" in the entire line, but this can be whatever you need, such as checking the nth word on the line etc.

If you want to select groups of lines beginning with a line that contains "start" and through a line that contains "end":

Code:
awk '/start/,/end/' myfile
That would also get a partial group of lines, starting with a line that contains "start" and terminating with end-of-file.
  #3 (permalink)  
Old 07-04-2002
jpl35 jpl35 is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 3
In the last sentence,
awk '/start/,/end/' myfile select from /start/ to /end/, what can i write for :

from /start/ to the end of file ?
Thanks
  #4 (permalink)  
Old 07-04-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
That is a little different. There are different approaches. One way is to set a flag on that will then test true for remainder of file processing:
Code:
awk '/string/ {p=1}; p==1 {print}' myfile
Or if you want to select lines starting with the line AFTER the found line:
Code:
awk '/string/ {p=1;next}; p==1 {print}' myfile
  #5 (permalink)  
Old 07-04-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Or, using the /from/,/to/ construct, you could use a to-string that you know would never be in the file, such as:
Code:
awk '/string/,/ue4R6TbWQ2Jk/' myfile
That would select lines beginning with a line containing "string" through a line containing ue4R6TbWQ2Jk or end-of-file, whichever is encountered first.
  #6 (permalink)  
Old 07-04-2002
jpl35 jpl35 is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 3
Thank's a lot to help me

can i have a pipe in my search string ?
  #7 (permalink)  
Old 07-04-2002
Jimbo
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Yes. The awk program is in single quotes, thus some protection from the shell. I just tested a search string that contains an embedded pipe character, and it worked without having to precede with backslash or anything.
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 02:23 PM.


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