Sponsored Content
Top Forums Shell Programming and Scripting Replace a string based on input Post 303038007 by Master_Mind on Tuesday 20th of August 2019 08:37:22 PM
Old 08-20-2019
Thanks RudiC for your help. But is there a way to tweak the existing code itself


Code:
final_var=$(echo "source_table_@ctry_final"| sed -e "s/\@ctry/${ctry_input}/")

why i am saying is because you if i give other than in that case only ctry only needs to be replaced

Code:
echo "other_table_@ctry_final"

I am trying to achieve madeingermany's method
Code:
final_var=$(echo "source_table_@ctry_final" | case $ctry_input in nz|usa|uk) sed "s/@ctry/$ctry_input/s/source_table/diff_table/";;*) sed "s/@ctry/$ctry_input/" ;; esac )


Last edited by Master_Mind; 08-21-2019 at 01:46 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

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

3. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

4. Shell Programming and Scripting

Find and replace string based on entries on another file

I have a file1 with different with multiple fields and records File2 has 2 fields. I want to find and replace strings in file1 based on file2 values (I Want an exact match i.e. for example: when searching for DT:3, Substr of DT:34 should not be matched) File2: DT:3 foo_err DT:34 bar_frr... (8 Replies)
Discussion started by: aydj
8 Replies

5. Shell Programming and Scripting

How to pad zeroes based on input string?

Hello everyone, I am comparing two floating point numbers by storing them in seperate files and then using difference command to verify,it is working fine. But I want to compare two values which will come at 4 precision places. ex: file1 Date,Count,Checksum... (7 Replies)
Discussion started by: karthik adiga
7 Replies

6. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

7. Shell Programming and Scripting

Replace string - searching from input file

Hi I need help with writing a script to change a string in a file. The script needs to read an input list (list.txt) file line by line searching for that string in a text.file. Once the string is found the last few words in the string should be replaced. eg list.txt will contain hello my... (6 Replies)
Discussion started by: sudobash
6 Replies

8. UNIX for Dummies Questions & Answers

Replace character string in txt file using input file(S)

Hi I have a large txt file on my AIX server and I need to replace some text using two other files. So filename1 has about 500 lines similar to: txtcode SYStem100 I have the string I want to change in string2 and the new stringname in string3. Does anyone know a way of doing this? I have... (1 Reply)
Discussion started by: Grueben
1 Replies

9. Shell Programming and Scripting

How to find previous string based on an input string?

Hi, I did some research but cannot find the right solution so hopefully someone can help me here. I have a long string format like: VAR=111:aaaa,222:bbb,333:ccc it could be VAR=111:aaa,222:bbb,333:ccc,444:ddd, etc what I looking for is eg. if I give ccc, it will return me 333... (2 Replies)
Discussion started by: netbanker
2 Replies

10. UNIX for Beginners Questions & Answers

Replace integer string in a variable based on month?

Hi Folks - Linux Version = Linux 2.6.39-400.128.17.el5uek x86_64 I have a process that determines the start and end load periods for an Oracle data load process. The variables used are as follows follows: They are populated like such: However, the load requires the month to be the... (11 Replies)
Discussion started by: SIMMS7400
11 Replies
GIT-REPLACE(1)							    Git Manual							    GIT-REPLACE(1)

NAME
git-replace - Create, list, delete refs to replace objects SYNOPSIS
git replace [-f] <object> <replacement> git replace -d <object>... git replace -l [<pattern>] DESCRIPTION
Adds a replace reference in .git/refs/replace/ The name of the replace reference is the SHA1 of the object that is replaced. The content of the replace reference is the SHA1 of the replacement object. Unless -f is given, the replace reference must not yet exist in .git/refs/replace/ directory. Replacement references will be used by default by all git commands except those doing reachability traversal (prune, pack transfer and fsck). It is possible to disable use of replacement references for any command using the --no-replace-objects option just after git. For example if commit foo has been replaced by commit bar: $ git --no-replace-objects cat-file commit foo shows information about commit foo, while: $ git cat-file commit foo shows information about commit bar. The GIT_NO_REPLACE_OBJECTS environment variable can be set to achieve the same effect as the --no-replace-objects option. OPTIONS
-f If an existing replace ref for the same object exists, it will be overwritten (instead of failing). -d Delete existing replace refs for the given objects. -l <pattern> List replace refs for objects that match the given pattern (or all if no pattern is given). Typing "git replace" without arguments, also lists all replace refs. BUGS
Comparing blobs or trees that have been replaced with those that replace them will not work properly. And using git reset --hard to go back to a replaced commit will move the branch to the replacement commit instead of the replaced commit. There may be other problems when using git rev-list related to pending objects. And of course things may break if an object of one type is replaced by an object of another type (for example a blob replaced by a commit). SEE ALSO
git-tag(1) git-branch(1) git(1) GIT
Part of the git(1) suite Git 1.7.10.4 11/24/2012 GIT-REPLACE(1)
All times are GMT -4. The time now is 03:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy