Sponsored Content
Top Forums Shell Programming and Scripting Last occurrence of code between two tags Post 302592329 by mirni on Monday 23rd of January 2012 02:12:55 PM
Old 01-23-2012
You did not modify Scrutinizer's code well. His code was as follows:
Code:
/usr/xpg4/bin/awk '$0~"<"resp{sect=1} 
   sect{p=p (p?RS:x) $0} 
   $0~"<user>"user && sect{found=1} 
   $0~"</"resp{if(found)n=p;found=0;p=x;sect=0}
   END{print n}' resp=response2 user=user1 infile

This is setting a variable 'resp' to have the value 'response2', and variable 'user' to a string 'user1'. Do not change the code inside the single quotes, just change the "response2" to what is your response actually named. If you are hunting a section
Code:
<ListABCResp>
...
</ListABCResp>

, with user "user1", then you'd do:
Code:
/usr/xpg4/bin/awk '$0~"<"resp{sect=1} 
   sect{p=p (p?RS:x) $0} 
   $0~"<user>"user && sect{found=1} 
   $0~"</"resp{if(found)n=p;found=0;p=x;sect=0}
   END{print n}' resp=ListABCResp user=user1 infile

However, I don't see why you would be getting "record too long" error... the code is appending to an internal variable. Have you tried to preprocess the file with the sed command and then pipe it to awk as suggested before?

Last edited by mirni; 01-23-2012 at 03:18 PM..
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace second occurrence only

HPUX /bin/sh (posix) I have a file as such cat dog mouse deer elk rabbit mouse rat pig I would like to replace the second occurrence of mouse in this file with mouse2. The rest of the file has to stay exactly as is. I'm not sure exactly where mouse might be (could be first,second,third... (5 Replies)
Discussion started by: lyoncc
5 Replies

2. Shell Programming and Scripting

number of occurrence

: i need a bash script to convert the displayed output 12 14 15 12 15 13 to 12 * 2 ,13 * 1,14*1,15*1 Thanks, nevil (2 Replies)
Discussion started by: nevil
2 Replies

3. Shell Programming and Scripting

Substitute first occurrence of keyword if occurrence between two other keywords

Assume a string that contains one or multiple occurrences of three different keywords (abbreviated as "kw"). I would like to replace kw2 with some other string, say "qux". Specifically, I would like to replace that occurrence of kw2 that is the first one that is preceded by kw1 somewhere in the... (4 Replies)
Discussion started by: M Gruenstaeudl
4 Replies

4. UNIX for Dummies Questions & Answers

Code for exact match to count occurrence

Hi all, I have an input file as below. I would like to count the occurrence of pattern matching 8th field for each line. Input: field_01 field_02 field_03 field_04 field_05 field_06 field_07 field_08 TA T TA T TA TA TA... (3 Replies)
Discussion started by: huiyee1
3 Replies

5. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies
SEQDIAG(1)						      General Commands Manual							SEQDIAG(1)

NAME
seqdiag - generate sequence-diagram image file from spec-text file. SYNOPSIS
seqdiag [options] file DESCRIPTION
This manual page documents briefly the seqdiag commands. seqdiag is generate sequence-diagram image file from spec-text file. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the Info files. --version show program's version number and exit -h, --help show this help message and exit -a, --antialias Pass diagram image to anti-alias filter -c FILE, --config=FILE read configurations from FILE -o FILE write diagram to FILE -f FONT, --font=FONT use FONT to draw diagram -T TYPE Output diagram as TYPE format SEE ALSO
The programs are documented fully by http://tk0miya.bitbucket.org/seqdiag/build/html/index.html AUTHOR
seqdiag was written by Takeshi Komiya <i.tkomiya@gmail.com> This manual page was written by Kouhei Maeda <mkouhei@palmtb.net>, for the Debian project (and may be used by others). May 21, 2011 SEQDIAG(1)
All times are GMT -4. The time now is 02:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy