Sponsored Content
Top Forums Shell Programming and Scripting Need help with sed to match and replace a string Post 302927205 by mallak on Monday 1st of December 2014 02:14:17 PM
Old 12-01-2014
Ravinder

Thanks for your response. I didn't got the expected result.

This is what I am trying to achieve

I have a file with many lines and among them Above are two lines.

Out of which I need to write a single liner so I can comment one line
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed scripting, match text within line and replace

New to sed... Have a file foo.txt (below). Need to replace text on 2 lines, but can only feed sed the first few characters of each line (all lines are unique). So, in my example, I have put '$' in place of what I need to figure out how to feed the whole line. What I have thus far: sed -e... (6 Replies)
Discussion started by: boolean2222
6 Replies

2. Shell Programming and Scripting

Match pattern and replace with string

hi guys, insert into /*<new>*/abc_db.tbl_name this is should be replaced to insert into /*<new>*/${new}.tbl_name it should use '.' as delimiter and replace is there any way to do it using sed (6 Replies)
Discussion started by: sol_nov
6 Replies

3. Shell Programming and Scripting

SED to replace exact match, not first occurrence.

Lets say I have file.txt: (Product:Price:QuantityAvailable) (: as delimiter) Chocolate:5:5 Banana:33:3 I am doing a edit/update function. I want to change the Quantity Available, so I tried using the SED command to replace 5, but my Price which is also 5 is changed instead. (for the Banana... (13 Replies)
Discussion started by: andylbh
13 Replies

4. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

sed Character match and replace

Hello All I am struck in the issue which I want to share with all of you. What I am trying to do is For every line in a file I have to replace a particular character from the given character in a file For Example Suppose the data is 1111x2222 1111x2222 2222y3333 1111x2222 I... (4 Replies)
Discussion started by: adisky123
4 Replies

7. Shell Programming and Scripting

Replace second match+awk/sed

I have a text file that looks like this: ----------------------------------------- sta WP00 time 10/23/2013 20:10:17 sensor trillium_240_2 0 583 add close sensor trillium_240_2 10/23/2013 20:10:17 sensor trillium_120 0 279 add close sensor trillium_120 10/23/2013 20:10:35... (11 Replies)
Discussion started by: klane
11 Replies

8. Shell Programming and Scripting

sed : replace Nth match in a file

I have a situation where a file "config.txt" looks like this Servername: OS: Serername: OS: Servername: OS: .... .... ... Servername: OS: looking for the sed syntax to replace the "Nth" occurrence of Servername (i would apply the same logic to OS as well), want to replace the Nth... (4 Replies)
Discussion started by: alldbest
4 Replies

9. Shell Programming and Scripting

Replace a string on specific lines which match a pattren

Hi Experts, I have a file which contains a pattern multiple times i.e. matchthispattren. If a line is matched with this pattern. I want a number in 1234567890 to 123456789 in that line. (Basically remove the last digit from that number. Please help. Thanks, Varun (1 Reply)
Discussion started by: varun22486
1 Replies

10. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies
TAP::Parser::Grammar(3pm)				 Perl Programmers Reference Guide				 TAP::Parser::Grammar(3pm)

NAME
TAP::Parser::Grammar - A grammar for the Test Anything Protocol. VERSION
Version 3.17 SYNOPSIS
use TAP::Parser::Grammar; my $grammar = $self->make_grammar({ stream => $tap_parser_stream, parser => $tap_parser, version => 12, }); my $result = $grammar->tokenize; DESCRIPTION
"TAP::Parser::Grammar" tokenizes lines from a TAP stream and constructs TAP::Parser::Result subclasses to represent the tokens. Do not attempt to use this class directly. It won't make sense. It's mainly here to ensure that we will be able to have pluggable grammars when TAP is expanded at some future date (plus, this stuff was really cluttering the parser). METHODS
Class Methods "new" my $grammar = TAP::Parser::Grammar->new({ stream => $stream, parser => $parser, version => $version, }); Returns TAP::Parser grammar object that will parse the specified stream. Both "stream" and "parser" are required arguments. If "version" is not set it defaults to 12 (see "set_version" for more details). Instance Methods "set_version" $grammar->set_version(13); Tell the grammar which TAP syntax version to support. The lowest supported version is 12. Although 'TAP version' isn't valid version 12 syntax it is accepted so that higher version numbers may be parsed. "tokenize" my $token = $grammar->tokenize; This method will return a TAP::Parser::Result object representing the current line of TAP. "token_types" my @types = $grammar->token_types; Returns the different types of tokens which this grammar can parse. "syntax_for" my $syntax = $grammar->syntax_for($token_type); Returns a pre-compiled regular expression which will match a chunk of TAP corresponding to the token type. For example (not that you should really pay attention to this, "$grammar->syntax_for('comment')" will return "qr/^#(.*)/". "handler_for" my $handler = $grammar->handler_for($token_type); Returns a code reference which, when passed an appropriate line of TAP, returns the lexed token corresponding to that line. As a result, the basic TAP parsing loop looks similar to the following: my @tokens; my $grammar = TAP::Grammar->new; LINE: while ( defined( my $line = $parser->_next_chunk_of_tap ) ) { foreach my $type ( $grammar->token_types ) { my $syntax = $grammar->syntax_for($type); if ( $line =~ $syntax ) { my $handler = $grammar->handler_for($type); push @tokens => $grammar->$handler($line); next LINE; } } push @tokens => $grammar->_make_unknown_token($line); } TAP GRAMMAR
NOTE: This grammar is slightly out of date. There's still some discussion about it and a new one will be provided when we have things better defined. The TAP::Parser does not use a formal grammar because TAP is essentially a stream-based protocol. In fact, it's quite legal to have an infinite stream. For the same reason that we don't apply regexes to streams, we're not using a formal grammar here. Instead, we parse the TAP in lines. For purposes for forward compatability, any result which does not match the following grammar is currently referred to as TAP::Parser::Result::Unknown. It is not a parse error. A formal grammar would look similar to the following: (* For the time being, I'm cheating on the EBNF by allowing certain terms to be defined by POSIX character classes by using the following syntax: digit ::= [:digit:] As far as I am aware, that's not valid EBNF. Sue me. I didn't know how to write "char" otherwise (Unicode issues). Suggestions welcome. *) tap ::= version? { comment | unknown } leading_plan lines | lines trailing_plan {comment} version ::= 'TAP version ' positiveInteger {positiveInteger} " " leading_plan ::= plan skip_directive? " " trailing_plan ::= plan " " plan ::= '1..' nonNegativeInteger lines ::= line {line} line ::= (comment | test | unknown | bailout ) " " test ::= status positiveInteger? description? directive? status ::= 'not '? 'ok ' description ::= (character - (digit | '#')) {character - '#'} directive ::= todo_directive | skip_directive todo_directive ::= hash_mark 'TODO' ' ' {character} skip_directive ::= hash_mark 'SKIP' ' ' {character} comment ::= hash_mark {character} hash_mark ::= '#' {' '} bailout ::= 'Bail out!' {character} unknown ::= { (character - " ") } (* POSIX character classes and other terminals *) digit ::= [:digit:] character ::= ([:print:] - " ") positiveInteger ::= ( digit - '0' ) {digit} nonNegativeInteger ::= digit {digit} SUBCLASSING
Please see "SUBCLASSING" in TAP::Parser for a subclassing overview. If you really want to subclass TAP::Parser's grammar the best thing to do is read through the code. There's no easy way of summarizing it here. SEE ALSO
TAP::Object, TAP::Parser, TAP::Parser::Iterator, TAP::Parser::Result, perl v5.12.1 2010-04-26 TAP::Parser::Grammar(3pm)
All times are GMT -4. The time now is 01:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy