awk between items including items


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk between items including items
# 1  
Old 12-12-2008
awk between items including items

OS=HP-UX ksh

The following works, except I want to include the <start> and <end> in the output.

Code:
awk -F '<start>' 'BEGIN{RS="<end>"; OFS="\n"; ORS=""} {print $2} somefile.log'

The following work in bash but not in ksh

Code:
sed -n '/^<start>/,/^<end>/{/LABEL$/!p}' somefile.log

# 2  
Old 12-12-2008
try this sed code
Code:
sed -ne '/^<start>/{
N
/LABEL$/!d
}
/<start>/,/<end>/p
' filename

# 3  
Old 12-12-2008
Quote:
Originally Posted by vidyadhar85
try this sed code
Code:
sed -ne '/^<start>/{
N
/LABEL$/!d
}
/<start>/,/<end>/p
' filename

I get:
Code:
# sed -ne '/^<SUMMARY/{N/LABEL$/!d}/<SUMMARY/,/\/SUMMARY/p' mylog.log
sed: Function /^<SUMMARY/{N/LABEL$/!d}/<SUMMARY/,/\/SUMMARY/p cannot be parsed.

Im actually using <SUMMARY as start point and /SUMMARY as end point.
# 4  
Old 12-12-2008
don't type it in same line..
just type as i showed
# 5  
Old 12-12-2008
With awk:

Code:
awk '/<start>/{p=1}/<end>/{print;p=0}p' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass an array to awk to sequentially look for a list of items in a file

Hello, I need to collect some statistical results from a series of files that are being generated by other software. The files are tab delimited. There are 4 different sets of statistics in each file where there is a line indicating what the statistic set is, followed by 5 lines of values. It... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

2. UNIX for Beginners Questions & Answers

Foreach not looping through all items

Hello, very new to this and have to use tcsh (not a choice at the moment). I need to convert files within sub directories. My foreach loops don't work. Directories are as follow: sub-001 --ses-T1 ---- anat --------File.nii --ses-T2 ----anat -------File.nii sub-002 and so on. ... (2 Replies)
Discussion started by: IlaBert
2 Replies

3. Shell Programming and Scripting

awk - function to return permutations of n items out of m

Hi, I'm trying to write an awk function that returns all possible permutations of n items chosen in a list of m items. For example, given the input "a,b,c,d,e" and 3, the function should return the following : a a a a a b a a c a b a a b b ... c a a c a b ... e e c e e d e e e (125... (21 Replies)
Discussion started by: cjnwl
21 Replies

4. UNIX for Dummies Questions & Answers

awk colon separated items

Hi, I need to filter my data based on items in column 23. Column 1 until column 23 are tab separated. This is how column 23 looks like: PRIMARY=<0/1:504:499,5:.:.:.:0.01:1:15:.> I want to extract lines if items 7 (separated by : ) in column 23 are more than 0.25 . In example above , item... (2 Replies)
Discussion started by: janshamsani
2 Replies

5. Shell Programming and Scripting

awk, help me - counting items and listing them

This is my first ever post... please help! :o I have two columns....here is part of the file... 12, 46798 6692, 46799 5710, ... (3 Replies)
Discussion started by: pelhabuan
3 Replies

6. Shell Programming and Scripting

Moving items to a new line

Hi, Let's I have the following strings (md5): 07177edf8261d28c6a003e583fcbe38c 0717c0037b3a20fc0f0998e673f228d5 0717d611a5d24374628b98e17fd00977,0717d611a5d24374628b98e17fd00977 07189a18afdae558bb5aadfe602e4a91 0719e97d481c239667f38a3e166bed74 071af3225fe50a1fdbb42c43aac313cc... (4 Replies)
Discussion started by: talfiq
4 Replies

7. Programming

Removing Items In A ListView

Hi everyone! So I have a listView on my Form named "officeView" I already have the code to add and update info into it, but Im having troubles deleting items out of it. :/ Now I know how to delete an Item from the listView, but I want the item before the deleted item to become automatically... (0 Replies)
Discussion started by: romeo5577
0 Replies

8. Shell Programming and Scripting

Matching 2 items in a string

Little lost here, I am trying to search a line for both values after the $ signs. My ultimate goal is to get percertage. <?php $string = "Something on sale for $4 and orginal price $10"; $strstr =. strstr($string, '$'); $strrchr =. strrchr($string, '$'); echo "$strstr<br>"; echo... (1 Reply)
Discussion started by: mrlayance
1 Replies

9. UNIX for Dummies Questions & Answers

queue items...

Hi everyone. I have a lot of programs i want to run on some data files, they need to be done sequentially. Often the output from one program is the input for the next. e.g $ progA data1 > data1.A $ progB data1.A > data1.AB $ progC data1.AB > data1.ABC repeat on data2, 3, 4, 5, 6 etc ... (4 Replies)
Discussion started by: Jay-pea
4 Replies

10. Shell Programming and Scripting

Comparing items in 2 files

Hi, I have 2 files with contents in them and I need to compare each item in each file. File1: item4 item5 File2: item2 item3 item5 item6 The items names can be of different lengths. If the items in the File1 are not in File2, delete the missing item in File1. The resulting... (12 Replies)
Discussion started by: ReV
12 Replies
Login or Register to Ask a Question