Sponsored Content
Top Forums Shell Programming and Scripting Bash string replacement - how to use regex? Post 302386665 by Ubuntu-UK on Wednesday 13th of January 2010 05:49:08 AM
Old 01-13-2010
Bash string replacement - how to use regex?

Hello

I have a bash script where I need to do a substring replacement like this:
variable2=${variable1/foo/bar}

However, I only want "foo" replaced if it is at the end of the line.

However, this does not work:
variable2=${variable1/foo$/bar}

as you can see I'm using the $ regex for end of line.

Does anyone know what the correct syntax is?

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

2. Shell Programming and Scripting

Replacement of string

Hi I have a text file which contains the following. AAA,BBB,CCC,DDD AAA,BBB,CCC,DDD AAA,BBB,CCC,DDD How can I replace all CCC with 888, with other contents inside the file remain unchange? Please advice Desired output: AAA,BBB,888,DDD AAA,BBB,888,DDD AAA,BBB,888,DDD (1 Reply)
Discussion started by: c0384
1 Replies

3. Shell Programming and Scripting

String replacement

Hi I am new to shell scripting but i manage to do some simple things. I am trying to replace a string in one file. I am using sed to replace but it is not permanently writing to the file, rather it is temporary. I want to know whether is there any another method to replace a string in a file... (7 Replies)
Discussion started by: reddybs
7 Replies

4. Shell Programming and Scripting

String replacement

I have one string string1=user/password:IP_ADDR:Directory I need to replace string1 value like store into string2 string2=user password:IP_ADDR:Directory i.e replace "/" character by '<space>' character But i wouldn't use any file in the meantime. Please help me......................... (6 Replies)
Discussion started by: mnmonu
6 Replies

5. Shell Programming and Scripting

Bash replacement to getchar

There's a replacement in bash for getchar or get functions of C and C++?Those functions read the next char avaliable in the input stream. I've tried something like: OLD_STTY=`stty -g` stty cbreak -echo look=`dd if=/dev/tty bs=1 count=1 2>/dev/null` stty $OLD_STTY But it is not working... (3 Replies)
Discussion started by: Asafe
3 Replies

6. Shell Programming and Scripting

String replacement

Hi All, I have below file which has data in below format. #$ | AB_100 | AB_300 ()| AB_4 @*(% | AB-789 i want o/p as below format. | AB_100 | AB_300 | AB_4 | AB-789 So here there is no standard format. How we can achieve the same in unix ? Regards, (3 Replies)
Discussion started by: gander_ss
3 Replies

7. Shell Programming and Scripting

filtering out duplicate substrings, regex string from a string

My input contains a single word lines. From each line data.txt prjtestBlaBlatestBlaBla prjthisBlaBlathisBlaBla prjthatBlaBladpthatBlaBla prjgoodBlaBladpgoodBlaBla prjgood1BlaBla123dpgood1BlaBla123 Desired output --> data_out.txt prjtestBlaBla prjthisBlaBla... (8 Replies)
Discussion started by: kchinnam
8 Replies

8. Shell Programming and Scripting

String replacement.

Dear Friends, I want to replace following line with given line. It should grep/search following string in a file (input.txt) M/M SRNO: 000M/6200-0362498 COSMETIC PRO MALE FEMALE Once found it should replace it to following string. T_DLHNNO: 000M/6200-0362498 ... (7 Replies)
Discussion started by: anushree.a
7 Replies

9. Shell Programming and Scripting

Use regex in replacement string in SED

Hi, I need to use the regex in the replacement string in SED command. something like sed -e ' s/\(^\{5\}\).\{150\}\(.*\)$/\10\{30\}1\{30\}A\{60\}B\{30\}\2/' abc which means for all the lines in file abc that starts with 5 characters, I need to replace character 6-151... (6 Replies)
Discussion started by: snowline84
6 Replies

10. Shell Programming and Scripting

sed regex backreference replacement

Hello, I want to rename multiple files and catch some points about backreference within sed and regex. Here is a part of my file list. Input: S92A.fa S92B.fa ... S96Z.fa S921.fa S922.fa ... S997.fa Note: The file names are not necessarily continuous from A~Z or 921 ~ 997, as some of the... (3 Replies)
Discussion started by: yifangt
3 Replies
Mojolicious::Routes::Match(3pm) 			User Contributed Perl Documentation			   Mojolicious::Routes::Match(3pm)

NAME
Mojolicious::Routes::Match - Routes visitor SYNOPSIS
use Mojolicious::Routes; use Mojolicious::Routes::Match; # Routes my $r = Mojolicious::Routes->new; $r->get('/foo')->to(action => 'foo'); $r->put('/bar')->to(action => 'bar'); # Match my $m = Mojolicious::Routes::Match->new(PUT => '/bar'); $m->match($r); say $m->captures->{action}; DESCRIPTION
Mojolicious::Routes::Match is a visitor for Mojolicious::Routes structures. ATTRIBUTES
Mojolicious::Routes::Match implements the following attributes. "captures" my $captures = $m->captures; $m = $m->captures({foo => 'bar'}); Captured parameters. "endpoint" my $endpoint = $m->endpoint; $m = $m->endpoint(Mojolicious::Routes->new); The routes endpoint that actually matched. "root" my $root = $m->root; $m = $m->root($routes); The root of the routes tree. "stack" my $stack = $m->stack; $m = $m->stack([{foo => 'bar'}]); Captured parameters with nesting history. METHODS
Mojolicious::Routes::Match inherits all methods from Mojo::Base and implements the following ones. "new" my $m = Mojolicious::Routes::Match->new(GET => '/foo'); my $m = Mojolicious::Routes::Match->new(GET => '/foo', $ws); Construct a new match object. "match" $m->match(Mojolicious::Routes->new, Mojolicious::Controller->new); Match against a routes tree. "path_for" my $path = $m->path_for; my $path = $m->path_for(foo => 'bar'); my $path = $m->path_for({foo => 'bar'}); my $path = $m->path_for('named'); my $path = $m->path_for('named', foo => 'bar'); my $path = $m->path_for('named', {foo => 'bar'}); my ($path, $ws) = $m->path_for; my ($path, $ws) = $m->path_for(foo => 'bar'); my ($path, $ws) = $m->path_for({foo => 'bar'}); my ($path, $ws) = $m->path_for('named'); my ($path, $ws) = $m->path_for('named', foo => 'bar'); my ($path, $ws) = $m->path_for('named', {foo => 'bar'}); Render matching route with parameters into path. SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojolicious::Routes::Match(3pm)
All times are GMT -4. The time now is 10:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy