Sponsored Content
Top Forums Shell Programming and Scripting sed doubt - search and substitute string from variable. Post 302455904 by dragon.1431 on Wednesday 22nd of September 2010 05:03:43 PM
Old 09-22-2010
MySQL sed doubt - search and substitute string from variable.

hi,
trying to learn more abt sed Smilie

i want to substitute a variable(a) with other variable(b) appended.

Read.txt contains:
Code:
home/test2/abc
home/test/root1

input.txt contains:
Code:
make test "home/test1/none"version="1.3"
wt's wrong test "home/test2/abc"version="1.0"
make save "home/test/root1"version="1.2"
make try "home/test3/user1"version="1.4"

code tried:
Code:
a=`cat read.txt`
for i in $a
do
b=_EDITED
sed -e "/$a/s///$a/$b/" input.txt
done

expected output:
Code:
make test "home/test1/none"version="1.3"
wt's wrong test "home/test2/abc_EDITED"version="1.0"
make save "home/test/root1_EDITED"version="1.2"
make try "home/test3/user1"version="1.4"

Thanks in advance Smilie

Last edited by dragon.1431; 09-22-2010 at 06:05 PM.. Reason: removed extra code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

2. Shell Programming and Scripting

search a string in a line and save it in a variable

Hi I want to read a file line by line and search for a particular string in each line(say for example string containing @ )and save that string into a variable. Can someone suggest me the way to implement it.I am using K- shell Thanks Ishita (5 Replies)
Discussion started by: Ishita
5 Replies

3. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

4. Shell Programming and Scripting

Trying to use a variable pulled from a for statement in a search string

Guys I am having trouble trying to pull some data from a file using a value returned from a for statement. Any help would greatly be apprecaited. I can't seem to get my script to pass the variable. I am trying to pull the 2 lines below the line that has the "pool name" so that i can get the... (5 Replies)
Discussion started by: scottzx7rr
5 Replies

5. 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

6. Shell Programming and Scripting

How to substitute variable in sed for special character?

Hi , I have input file like below Hi this is "vinoth". Hi happy to work with 'unix' USA(united states of America) My script variables are below : Dquote=Ộ Squote=&#$567 Obrac=&^986 Cbrac=&^745 I want to read the variables in my SED command to replace the double quote,single... (9 Replies)
Discussion started by: vinothsekark
9 Replies

7. Shell Programming and Scripting

String search between patterns using sed

Hi, I am trying to find a way to get sed/awk/grep to help me find a string in a log file that exists between two datestamps and then print the preceding datestamp up to the next datestamp. Here is an example of my logfile: +++ 2013/03/28 17:01:37.085 SIGNALING HIGH ACTIVE Failure Response... (5 Replies)
Discussion started by: raytx
5 Replies

8. Shell Programming and Scripting

Search for 2 string in 2 lines with sed ?

Hi ! I want to search a string in all lines with sed. If that string is there, i want to look for an other string in the next line.If that string is there i want to put an other line under it. eg: aaa bbb ccc ddd cat bla.txt | sed -e '/aaa/a\' -e ' \!!!' in the upper case, i would... (6 Replies)
Discussion started by: fugitivus
6 Replies

9. Shell Programming and Scripting

[sed]: Substitute a string with a multiline value

Dear all, I try to replace a string of characters in a file (MyFile.txt) by a multiline value of the variable "Myvar": $ cat MyFile.txt DESCRIPTION '@TargetTable SCHEMA' ( @InputFlowDef ); $ The content of Myvar: $ echo "$Myvar" col1 , col2 , col3 $ (4 Replies)
Discussion started by: dae
4 Replies

10. Shell Programming and Scripting

Search for string in column using variable: awk

I'm interested to match column pattern through awk using an external variable for data: -9 1:751343:T:A -9 0 T A 0.726 -5.408837e-03 9.576603e-03 7.967536e-01 5.722312e-01 -9 1:751756:T:C -9 0 T C 0.727 -5.360458e-03 9.579447e-03 7.966977e-01 5.757858e-01... (7 Replies)
Discussion started by: genome
7 Replies
Path::Dispatcher::Match(3pm)				User Contributed Perl Documentation			      Path::Dispatcher::Match(3pm)

NAME
Path::Dispatcher::Match - the result of a successful rule match SYNOPSIS
my $rule = Path::Dispatcher::Rule::Tokens->new( tokens => [ 'attack', qr/^w+$/ ], block => sub { my $match = shift; attack($match->pos(2)) }, ); my $match = $rule->match("attack dragon"); # introspection $match->path # "attack dragon" $match->leftover # empty string (populated with prefix rules) $match->rule # $rule $match->positional_captures # ["attack", "dragon"] (decided by the rule) $match->pos(1) # "attack" $match->pos(2) # "dragon" $match->run # attack("dragon") DESCRIPTION
If a Path::Dispatcher::Rule successfully matches a path, it creates one or more "Path::Dispatcher::Match" objects. ATTRIBUTES
rule The Path::Dispatcher::Rule that created this match. path The path that the rule matched. leftover The rest of the path. This is populated when the rule matches a prefix of the path. positional_captures Any positional captures generated by the rule. For example, Path::Dispatcher::Rule::Regex populates this with the capture variables. named_captures Any named captures generated by the rule. For example, Path::Dispatcher::Rule::Regex populates this with named captures. parent The parent match object, if applicable (which may be set if this match is the child of, for exampl, a Path::Dispatcher::Rule::Under prefix) METHODS
run Executes the rule's codeblock with the same arguments. pos($i) Returns the $ith positional capture, 1-indexed. perl v5.12.4 2011-08-30 Path::Dispatcher::Match(3pm)
All times are GMT -4. The time now is 11:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy