Sponsored Content
Top Forums Shell Programming and Scripting Match from one pattern to second occurrence of second pattern Post 302760887 by jnojr on Thursday 24th of January 2013 05:45:18 PM
Old 01-24-2013
Question Match from one pattern to second occurrence of second pattern

Given an XML file that contains (NOT "consists of"):

Code:
                </dict>
                <key>system.</key>
                <dict>
                        <key>rule</key>
                        <string>default</string>
                </dict>
                <key>system.burn</key>
                <dict>
                        <key>class</key>
                        <string>allow</string>
                        <key>comment</key>
                        <string>For burning media.</string>
                        <key>default-button</key>
                        <dict>
                                <key>ar</key>
                                <string>نسخ قرص</string>
                                <key>ca</key>
                                <string>Gravar</string>
                                <key>cs</key>
                                <string>Vypálit</string>
                                <key>da</key>
                                <string>Brćnd</string>
                                <key>de</key>

I want to isolate and operate on the lines between <key>system.burn</key> and the second occurrence of <dict>, so:

Code:
                        <key>class</key>
                        <string>allow</string>
                        <key>comment</key>
                        <string>For burning media.</string>
                        <key>default-button</key>

Now, sed -n '/<key>system.burn<\/key>/,/<dict>/2 p' /etc/authorization would get me what I want... except I'm on a Mac, and so do not have GNU see. That gets me "invalid command code 2" I can delete the 2 and wind up with a valid pattern, but it only returns:

Code:
		<key>system.burn</key>
		<dict>

I don't want to just return the six lines after <key>system.burn</key> as I cannot be positive that there will always just be six lines.

I have a feeling awk is going to be the answer here, but I've got a long curve to climb with awk. I'm proud of myself for being able to print $2 or even $NF, so that tells you how advanced I am there :-P

Last edited by jnojr; 01-24-2013 at 07:05 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count the number of occurrences of a pattern between each occurrence of a different pattern

I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'. Here's a portion of the text I'm trying to parse: lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb registrations: key 4156 4353 0000 0000 ... (3 Replies)
Discussion started by: slipstream
3 Replies

2. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

3. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

4. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

5. Shell Programming and Scripting

Insert new pattern in newline after the nth occurrence of a line pattern - Bash in Ubuntu 12.04

Hi, I am getting crazy after days on looking at it: Bash in Ubuntu 12.04.1 I want to do this: pattern="system /path1/file1 file1" new_pattern=" data /path2/file2 file2" file to edit: data.db - I need to search in the file data.db for the nth occurrence of pattern - pattern must... (14 Replies)
Discussion started by: Phil3759
14 Replies

6. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

7. Shell Programming and Scripting

sed : match one pattern then the next consecutive second pattern not working

Ive used this snippet of code on a solaris box thousands of times. But it isnt working on the new linux box sed -n '/interface LoopBack0/{N;/ ip address /p;}' *.conf its driving me nuts !! Is there something Im missing ? (7 Replies)
Discussion started by: popeye
7 Replies

8. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

9. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

10. Shell Programming and Scripting

awk command to get file content until 2 occurrence of pattern match

AWK command to get file content until 3 occurrence of pattern match, INPUT FILE: JMS_BODY_FIELD:JMSText = <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <custOptIn xmlns="http://com/walm/ta/cu/ccs/xml2"> <person>Romi</person> <appName>SAP</appName> </custOptIn> ... (4 Replies)
Discussion started by: prince1987
4 Replies
BRASERO(1)						      General Commands Manual							BRASERO(1)

NAME
brasero - Simple and easy to use CD/DVD burning application for the Gnome Desktop SYNOPSIS
brasero [options] [uri] [uri] ... DESCRIPTION
This manual page documents briefly the brasero command. rasero is a disc burning application. It is designed to be simple and easy to use. It allows to create data CD/DVD, audio CD, to copy CD/DVD and to burn images. It has some nices features, such as a song, image and video previewer. It can also search for files (thanks to beagle) and display a playlist and its contents. OPTIONS
This program follows 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. -p, --project=PROJECT Open the specified project. -a, --audio Open an empty audio project. -d, --data Open an empty data project. -c, --copy=PATH Copy a disc. -j, --cover=PATH Cover to use. -o, --video Open a video project adding the URIs given on the command line. -i, --image=PATH Uri of an image file or a cue file to be burnt (autodetected). -e, --empty Force brasero to display the project selection page. -b, --blank Open the blank disc dialog. -k, --check Open the check disc dialog. -n, --ncb Open a data project with the contents of burn:/// URI. -r, --burn-and-remove-project=PATH Burn the specified project and REMOVE it. -g, --debug Display debug statements on stdout. --display=DISPLAY X display to use. -?, --help Show summary of options. -v, --version Show version of program. AUTHOR
Brasero manual page was written by Philippe Rouquier <philippero@libertysurf.fr> and Luis Medinas <lmedinas@gmail.com>. GNOME
January 11, 2009 BRASERO(1)
All times are GMT -4. The time now is 01:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy