Sponsored Content
Top Forums Shell Programming and Scripting sed - String substitution within specified section in ini type file Post 302881492 by kurumi on Sunday 29th of December 2013 10:00:13 PM
Old 12-29-2013
this is a general algorithm for getting the specific block you want. you can use it in any language you want.

Code:
#!/usr/bin/env ruby -w


match = false
str   = ""
File.open("file").each_line do|line|      # open file for processing
  if match and line[/^$/]                 # if match and empty line
    puts str                              # print string
    break
  end
  if line[/handler_syncserver_errors/]    # set match if found your string
    match = true   
  end
  if match                                # gather your lines if match
    str = str + line
  end
end

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sed String Substitution

Hi! I've the following script code with an input parameter: sed 's/oldstring/$1/g' myfile > newfile (I launch it with comman line: $ MyShell newstring) Problem: the substituion doesn't work (oldstring becomes $1, instead of newstring). How could I solve this situation? Thanks, ... (2 Replies)
Discussion started by: pciatto
2 Replies

2. Shell Programming and Scripting

Sed - substitution for whole string

Hello I have several files where a string similar to this appears: /home/workload/bin/ProcDly/scrpts/T54.sh > $LOG I need to change it to something like this: $VARIABLE > $LOG However, due to the configuration of the rest of the files, I should only find this string by the... (4 Replies)
Discussion started by: Scarlos
4 Replies

3. Shell Programming and Scripting

sed & awk--get section of file based 2 params

I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't... (12 Replies)
Discussion started by: Andy Cook
12 Replies

4. Shell Programming and Scripting

Using Sed to duplicate a section of a file....

hello all, I have a file like this: section 1 blah1 blah2 section 2 blah1 blah2 section 3 blah1 blah2 and I want to use sed to duplicate section 2, like this: section 1 blah1 blah2 section 2 blah1 blah2 section 2 blah1 (2 Replies)
Discussion started by: nick26
2 Replies

5. Shell Programming and Scripting

Problem with sed string substitution

Hi, heres my problem: echo "aaaa(aaaa(aaa" | sed 's/a.*(//g' gives aaa but it should give aaaa(aaa .*( should find any string to the appearance of (, but it finds any string to the last appearance, any idea why, and how to do this? and what if the string ist... (2 Replies)
Discussion started by: funksen
2 Replies

6. Shell Programming and Scripting

SED 4.1.4 - INI File Change Problem in Variables= in Specific [Sections] (Guru Help)

GNU sed version 4.1.4 on Windows XP SP3 from GnuWin32 I think that I've come across a seemingly simple text file change problem on a INI formatted file that I can't do with SED without side effects edge cases biting me. I've tried to think of various ways of doing this elegantly and quickly... (5 Replies)
Discussion started by: JakFrost
5 Replies

7. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

8. Shell Programming and Scripting

Trouble with sed and ini file parsing

hi people, i'm having a hard time trying to extract a list of vars delimited by section inside a ini file ... let's consider this ini file : ; config file DESC = "channel synchro TGG01" DMM_VER = DMM23 PATH_FIFO = /users/tgg00/fifo QRT = BTS01.TGG.01.2 MODE_TRACE... (5 Replies)
Discussion started by: odium74
5 Replies

9. Shell Programming and Scripting

Find string in XML file, copy contents of section

I am new, really new to bash scripts. I want to search an XML file for a certain string, say "1234567890" Once found, I want to copy the entire contents from the previous instance of the string "Entity" to the next instance of "/Entity" to a txt file. And then continue searching for the... (4 Replies)
Discussion started by: jrfiol
4 Replies

10. Shell Programming and Scripting

sed substitution or awk, need to direct change the file

I want change the file when the line contains $(AA) but NOT contains $(BB), then change $(AA) to $(AA) $(BB) eg: $(AA) something $(AA) $(BB) something (7 Replies)
Discussion started by: yanglei_fage
7 Replies
VGRINDEFS(5)						      BSD File Formats Manual						      VGRINDEFS(5)

NAME
vgrindefs -- language definition data base for vgrind(1) SYNOPSIS
vgrindefs DESCRIPTION
The vgrindefs file contains all language definitions for vgrind(1). The data base is very similar to termcap(5). FIELDS
The following table names and describes each field. Name Type Description pb str regular expression for start of a procedure bb str regular expression for start of a lexical block be str regular expression for the end of a lexical block cb str regular expression for the start of a comment ce str regular expression for the end of a comment sb str regular expression for the start of a string se str regular expression for the end of a string lb str regular expression for the start of a character constant le str regular expression for the end of a character constant tl bool present means procedures are only defined at the top lexical level oc bool present means upper and lower case are equivalent kw str a list of keywords separated by spaces EXAMPLES
The following entry, which describes the C language, is typical of a language entry. C|c::pb=^d?*?d?pd?(a?):bb={:be=}:cb=/*:ce=*/:sb=":se=e": :lb=':le=e':tl: :kw=asm auto break case char continue default do double else enum extern float for fortran goto if int long register return short sizeof static struct switch typedef union unsigned while #define #else #endif #if #ifdef #ifndef #include #undef # define else endif if ifdef ifndef include undef: Note that the first field is just the language name (and any variants of it). Thus the C language could be specified to vgrind(1) as "c" or "C". Entries may continue onto multiple lines by giving a as the last character of a line. Capabilities in vgrindefs are of two types: Boolean capabilities which indicate that the language has some particular feature and string capabilities which give a regular expression or keyword list. REGULAR EXPRESSIONS
vgrindefs uses regular expression which are very similar to those of ex(1) and lex(1). The characters `^', `$', `:' and `' are reserved characters and must be "quoted" with a preceding '' if they are to be included as normal characters. The metasymbols and their meanings are: $ the end of a line ^ the beginning of a line d a delimiter (space, tab, newline, start of line) a matches any string of symbols (like .* in lex) p matches any alphanumeric name. In a procedure definition (pb) the string that matches this symbol is used as the procedure name. () grouping | alternation ? last item is optional e preceding any string means that the string will not match an input string if the input string is preceded by an escape character (). This is typically used for languages (like C) which can include the string delimiter in a string by escaping it. Unlike other regular expressions in the system, these match words and not characters. Hence something like "(tramp|steamer)flies?" would match "tramp", "steamer", "trampflies", or "steamerflies". KEYWORD LIST
The keyword list is just a list of keywords in the language separated by spaces. If the "oc" boolean is specified, indicating that upper and lower case are equivalent, then all the keywords should be specified in lower case. FILES
/usr/share/misc/vgrindefs File containing terminal descriptions. SEE ALSO
troff(1), vgrind(1) HISTORY
The vgrindefs file format appeared in 4.2BSD. 4.2 Berkeley Distribution June 6, 1993 4.2 Berkeley Distribution
All times are GMT -4. The time now is 05:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy