Sponsored Content
Top Forums Shell Programming and Scripting How to edit file sections that cross multiple lines? Post 302386603 by Narnie on Tuesday 12th of January 2010 11:10:25 PM
Old 01-13-2010
MySQL Needing help with searching and replace in a file (sed?)

Hello,

I'm wondering where I could go to learn how to edit file sections that cross multiple lines. I'm wanting to write scripts that will add Gnome menu entries for all users on a system for scripts I write, etc. I can search an replace simple examples with sed, but this seems more complex.

I am on a 'doz system in a hotel right now so I can't post the actual file, but the Gnome menu entry has a structure similar to this:

Code:
<Menu>
    <Name>Accessibility</Name>
    <Directory>Accessibility.directory</Directory>
    <Include>
      <And>
        <Category>Accessibility</Category>
        <Not><Category>Settings</Category></Not>
      </And>
    </Include>
    <Exclude>
      <Filename>dasher.desktop</Filename>
    </Exclude>
  </Menu>

Say I need to change the markups for the dasher.desktop file from <Exclude> to <Include> and </Exclude> to </Include>?

What If I wanted to add a new <Include></Include> section for a new .desktop file?

Compounding this is that there is variable whitespace indentation depending on how deep into the structure one needs to go and it would be nice to keep the formatting for readability and a nicer, more polished look.

Basically, what is the technique for finding something, and then modifying something on lines above and/or below it OR finding a section, and then adding something on a line below that section without modifying that line in the process.

I don't mind learning myself, but I need pointed in the right direction. I'm not sure where to start. This seems like a bit of a big job for sed. If someone would want to code an example, I'm up for that too as I can learn from that (hey, learning is fun, right?)

With thanks,
Narnie

Last edited by Narnie; 01-13-2010 at 01:57 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handle Configuration File with same name of Parameter in multiple Sections

Hi I have a config file with multiple section and a parameter with the same name in each section. I need to read each parameter for distinct section. Parameter = 1 .... Parameter = 2 .... Parameter = 4 .... Tried this: grep -m1 '^*ProcessorsNumber' ServiceBrokerFramework.cfg |... (7 Replies)
Discussion started by: potro
7 Replies

2. UNIX for Advanced & Expert Users

extract multiple sections of a file

I have a file that I need to parse multiple sections from the file. The file contains multiple lines that start with ST (Abunch of data) Then the file contains multiple lines that start with SE (Abunch of data) SE*30*0001 ... (1 Reply)
Discussion started by: rgentis
1 Replies

3. Shell Programming and Scripting

extract multiple sections of file

I have a file that I need to parse multiple sections from the file. The file contains multiple lines that start with ST (Abunch of data) Then the file contains multiple lines that start with SE (Abunch of data) SE*30*0001 ST*810*0002 I need all of the lines between and including these.... (6 Replies)
Discussion started by: rgentis
6 Replies

4. Shell Programming and Scripting

Edit number of lines in a file to single line

Greetings, I have a file: hostnames.txt which has - # cat hostnames.txt machine1 machine2 I need the output to be saved to a variable as: HOSTNAMELIST=machine1,machine2 Please advise. Thanks, Chiru (3 Replies)
Discussion started by: chiru_h
3 Replies

5. Shell Programming and Scripting

swaping sections of lines

Is it possible to do this with sed? Go from this: 958211 XXYYXXYYXX file1 file2 file3 958897 XXYYXXYYXX file1 file2 To this: file1 file2 file3 XXYYXXYYXX 958211 file1 file2 XXYYXXYYXX 958897 The only thing consistant is XXYYXXYYXX. The numbers and files vary in length. I have seen I... (5 Replies)
Discussion started by: crowman
5 Replies

6. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

7. Shell Programming and Scripting

Need Help to Edit multiple column of a file

Hello Team, I want to know if there is any one liner command , using which I can edit multiple column of a file. input file input.txt (comma separated), taran, 12.45, uttam, 23.40, babay karan, 12.45, raju, 11.40, rahulg I want to update, 2nd and 4th column, but want all those column... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

8. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

9. Shell Programming and Scripting

Edit and replace the multiple values in a file in one iteration

Hi All, I am preserving OLD and NEW values and want to replace the values in one go instead of using multiple sed and mv commands. Please help. echo "\nEnter the new qStart time '${CODE}' - (Hit Enter for No Change): \c" read NEW echo "\nEnter the new qStop time '${CODE}' - (Hit Enter for... (2 Replies)
Discussion started by: sdosanjh
2 Replies

10. Shell Programming and Scripting

Edit lines in file preserving part of it

Hello: I have the following HTML table: <table> <thead> <tr> <th>Code</th> <th>Percentage</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>30%</td> </tr> <tr> <td>2</td> ... (3 Replies)
Discussion started by: Cacializ
3 Replies
MENUFILE(5)							File Formats Manual						       MENUFILE(5)

NAME
menufile - entry in the Debian menu system SYNOPSIS
~/.menu/* /etc/menu/* /usr/lib/menu/* /usr/share/menu/* /usr/share/menu/default/* DESCRIPTION
Menu files add entries to the Debian menu system. The system administrator can place menu files in /etc/menu/ to override menu files that packages add to /usr/share/menu/ . The user can place menu files in ~/.menu/ to override all other menu files. Please read the Debian menu manual available in /usr/share/doc/menu/html for the complete specification of menu files. The menu files are usually named after the Debian package that contains the programs listed in them. In it, you can list several "menu entries" that specify a specific item in the menu structure. Each menu entry specifies which packages it depends on; if that package are not installed, the menu entry will be ignored by update-menus(1). (In a menu entry you can specify pseudo-packages that start with "local."; update-menus will always use those menu entries). If you wish to remove an item from the menu entirely, make an empty menu file with the same name as the file you want to override. Examples Dosemu could install the following menu file as /usr/share/menu/dosemu: ?package(dosemu):needs="text" section="Applications/Emulators" title="Dosemu" command="dosemu" ?package(dosemu):needs="X11" section="Applications/Emulators" title="Dosemu" command="xdos" The system administrator wants to override this file to change how dosemu is run, so /etc/menu/dosemu is created: ?package(dosemu):needs="text" section="Applications/Emulators" title="Dosemu" command="dosemu -A" ?package(dosemu):needs="X11" section="Applications/Emulators" title="Dosemu" command="xdos -A" A user does not want Dosemu to appear in the menus at all, so the user creates an empty file named ~/.menu/dosemu. FORMAT
A menu file consists of 0 or more lines of the following format: ?package(package-name):var1=value1 var2=value2 ... needs Specify what kind of environment the program require. This variable must be defined, and should be one of the following: needs="text" Program requires a terminal needs="x11" Program requires a X server needs="vc" Program requires a Linux console (i.e.: svgalib programs) needs="wm" The program is a window manager. needs="fvwmmodule" The program is a fvwm compatible module. section The section in which the menu entry should appear. See MENU LAYOUT for preferred section names. icon An icon for this menu entry. If no icon is available, just don't define this. title The title of the program that will appear on the menus. Keep it short. If two menu entries share the same title and section, the one that best fits the available display will be used. So in the example above with two menu entries that both have the menu id "title", if X is available, the X11 one will be used; otherwise the text one will be used. Must be defined. command The command to be executed when this menu entry is selected. hints A comma-separated list of hints on how grouping menu entries; see the manual. MENU LAYOUT
The authoritative list of Debian's menu structure is maintained in the Debian Menu sub-policy document which is part of the Debian Policy package. The menu structure below is included only for convenience. Please do not put your packages into any other sections. Use `/' to separate sub-menu names, for example, "Applications/Editors" or "Games/Arcade". Applications Accessibility Amateur Radio Data Management Editors Education Emulators File Management Graphics Mobile Devices Network Communication File Transfer Monitoring Web Browsing Web News Office Programming Project Management Science Astronomy Biology Chemistry Data Analysis Electronics Engineering Geoscience Mathematics Medicine Physics Social Shells Sound System Administration Hardware Language Environment Monitoring Package Management Security Terminal Emulators Text TV and Radio Viewers Video Web Development Games Action Adventure Blocks Board Card Puzzles Simulation Strategy Tools Toys Help Screen Saving Locking Window Managers FVWM Modules Window Maker NOTES
If you want to specify an icon or hotkey for a sub-menu (for example, the Editors sub-menu), just use the same syntax but leave the command empty: ?package(mypackage):needs="X11" section="Applications" icon="icon.xpm" hotkey="E" title="Editors" Whenever any menu files are changed, you must run update-menus(1) FILES
(Earlier listed files override later files with the same names.) ~/.menu/* Menu files added by the user. /etc/menu/* Menu files added by the system administrator. /usr/lib/menu/* Architecture-dependant menu files provided by other Debian packages. /usr/share/menu/* Architecture-independant menu files provided by other Debian packages. /usr/share/menu/default/* Menu files provided by the menu package. AUTHORS
Joost Witteveen <joostje@debian.org>, based on work by Lars Wirzenius <liw@iki.fi>. Now maintained by Bill Allombert <ballombe@debian.org>. (Man page by Joey Hess, <joeyh@debian.org>) SEE ALSO
update-menus(1), /usr/share/doc/menu/html/index.html DEBIAN
File Formats MENUFILE(5)
All times are GMT -4. The time now is 04:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy