Sponsored Content
Top Forums Shell Programming and Scripting sed replace is giving me sore thumbs Post 303040889 by manas_ranjan on Friday 8th of November 2019 08:09:11 AM
Old 11-08-2019
sed replace is giving me sore thumbs

I want to replace only the exact match of string inside the file with another value during the run time.

So,
I have a file filename.txt
where contents are:

Code:
version="1.0.7", 
url="https://google.com/_api/version=GBMaster"

now in my script
I have variable and tried to replace the value of that variable in version line with double quotes and comma.

Code:
new_version="1.0.7.1234567"
sed -i -e "s/version=.*/version="""$new_version""",/g"  filename.txt

the above kind of working, but it also replace the version in url and also not adding (double quotes) like below
Code:
version=1.0.7.1234567, 
url="https://google.com/_api/version=1.0.7.1234567"

I tried a lot variety of seds to make sure my file should only replace version= in version line not in URL.
that includes \< \> or ^. None of them are working.

I would like my o/p to be like below after sed
Code:
version="1.0.7.1234567", 
url="https://google.com/_api/version=GBMaster"

--- Post updated at 08:09 AM ---

never mind, guys fixed it.

Last edited by manas_ranjan; 11-08-2019 at 09:11 AM.. Reason: found the solution looking for.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using sed to replace ' with `

Dear All, I am writting a shell script program on AIX server version 5.3 in which I am doing cleaningprocess for files in which I am trying to replace ' with ` . and for this I am using following command: sed -e 's//$/g' -e 's/\\/\//g' -e 's/'/`/g' $file >>... (2 Replies)
Discussion started by: mr_dba01
2 Replies

2. UNIX for Dummies Questions & Answers

Delete files Recursively *thumbs*.jpg

Greetings, I need to delete all files that contain the word thumbs. Those files are spread all throughout sub-directories in a file directory tree. Is there a script or single line command that will find all files with the word thumbs, and simply delete the file? For example: Delete... (4 Replies)
Discussion started by: ..Chris..
4 Replies

3. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

4. UNIX for Dummies Questions & Answers

sed - how to replace ' with \'

Hello, I have problem I can't solve. My task is to replace all apostrophes in my music library eg. I'm free to I/'m free I can select ' (apostrophe), but I can't find "to" section.. '/ echo "I'm free" | sed 's/'\''/what_shell_i_put_here/g' many thanks in advance, peter (3 Replies)
Discussion started by: piogac6088
3 Replies

5. Shell Programming and Scripting

How to use sed to replace the a string in the same file using sed?

How do i replace a string using sed into the same file without creating a intermediate file? (7 Replies)
Discussion started by: gomes1333
7 Replies

6. Shell Programming and Scripting

Sed in vi - \r and \n not giving desired results

I use many different machines at work, each with different versions of o/s's and installed applications. Sed in vi is particularly inconvenient in the sense that sometimes it will accept the "\r" as a carriage return, sometimes not. Same thing with "\n". For instance, if I have a list of hosts... (7 Replies)
Discussion started by: MaindotC
7 Replies

7. Shell Programming and Scripting

sed -i option giving error no such file or directory

I created a shell with sed -i option. It is giving error - No such file or directory Ex - sed -i 's/yes/no' yes.txt sed -i 's/why/where' yes.txt sed -i 's/when/how' yes.txt Error - :No such file or directory When I run single line in my script say sed -i 's/yes/no' yes.txt... (10 Replies)
Discussion started by: yahoo
10 Replies

8. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

9. UNIX for Dummies Questions & Answers

sed Replace

I have a file whose output words are always like this: aaaa bbbb cccc dddd. Trying to arrange the data so that there are 2 columns such that the 1st word become the 1st column like this: aaaa aaaa aaaa bbbb aaaa cccc aaaa dddd Trying to use awk... (8 Replies)
Discussion started by: jimmyf
8 Replies
Locale::Codes::LangExt(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangExt(3pm)

NAME
Locale::Codes::LangExt - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangExt; $lext = code2langext('acm'); # $lext gets 'Mesopotamian Arabic' $code = langext2code('Mesopotamian Arabic'); # $code gets 'acm' @codes = all_langext_codes(); @names = all_langext_names(); DESCRIPTION
The "Locale::Codes::LangExt" module provides access to standard codes used for identifying language extensions, such as those as defined in the IANA language registry. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default IANA language registry codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language extensions. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langext('acm','alpha'); $lext = code2langext('acm',LOCALE_LANGEXT_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from the IANA language registry, such as 'acm' for Mesopotamian Arabic. This is the default code set. ROUTINES
code2langext ( CODE [,CODESET] ) langext2code ( NAME [,CODESET] ) langext_code2code ( CODE ,CODESET ,CODESET2 ) all_langext_codes ( [CODESET] ) all_langext_names ( [CODESET] ) Locale::Codes::LangExt::rename_langext ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangExt::add_langext ( CODE ,NAME [,CODESET] ) Locale::Codes::LangExt::delete_langext ( CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_alias ( NAME ,NEW_NAME ) Locale::Codes::LangExt::delete_langext_alias ( NAME ) Locale::Codes::LangExt::rename_langext_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::delete_langext_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.iana.org/assignments/language-subtag-registry The IANA language subtag registry. AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangExt(3pm)
All times are GMT -4. The time now is 07:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy