Sponsored Content
Top Forums Shell Programming and Scripting grep a pattern and replace a value in it and write to the same file. Post 302352383 by skmdu on Friday 11th of September 2009 06:57:43 AM
Old 09-11-2009
since i could not get your expectation clearly,
Here am giving some solution

$cat file

DEV_1_SOURCE_DATABASE=server1
DEV_1_SOURCE_AUDIT_DATABASE= server1
DEV_1_TARGET_DATABASE=server4
DEV_1_TARGET_AUDIT_DATABASE=server4

DEV_2_SOURCE_DATABASE=server2
DEV_2_SOURCE_AUDIT_DATABASE= server2
DEV_2_TARGET_DATABASE=server5
DEV_2_TARGET_AUDIT_DATABASE=server5

Solution 1:

script1.sh
a=` cat file | grep -w "DEV_2_TARGET_DATABASE" | cut -d '=' -f 2`
sed "s/\($a\)/newdb/g" file > file1
mv file1 file

The above script will take the value assigned for DEV_2_TARGET_DATABASE, and substitute that value i.e "server5" to newdb in the whole file content. ( even for DEV 4 or DEV 3)

Solution 2:

If you want to substitute only DEV_2_TARGET_DATABASE=server5 to DEV_2_TARGET_DATABASE=newdb

sed "s/\(DEV_2_TARGET_DATABASE=\)\(.*\)/\1newdb/g" file

Hope this helps..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help needed .. Unable to write the data to new file after matching the pattern

Hi, i am pretty new to Unix environment ..... Can i get some help from any of you guyz on writing Unix script. my requirement is like reading a csv file, finding a specific pattern in the lines and repalce the string with new string and write it to another file. My file is file ABC123.dat... (3 Replies)
Discussion started by: prashant_jsw
3 Replies

2. Shell Programming and Scripting

How to replace some content of a file and write with a new name

Hi I have a control file which looks like this LOAD DATA INFILE '/home/scott/XXX.dat' PRESERVE BLANKS ............. ............. how can i change the content of this file and replace the file in the second line with anothe file name and write it back with another name to the disk? ... (5 Replies)
Discussion started by: mwrg
5 Replies

3. Shell Programming and Scripting

How to delete a string pattern in a file and write back to the same file

I have a control file which looks like this LOAD DATA INFILE '/array/data/data_Finished_T5_col_change/home/oracle/emp.dat' PRESERVE BLANKS INTO TABLE SCOTT.EMP FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS (................. ..................) How can i edit the... (1 Reply)
Discussion started by: mwrg
1 Replies

4. Shell Programming and Scripting

Replace a particular pattern in a file

Hi , I have a requirement where i have this file abcd $$xyz=123 $$zef=789 $$mno=123 $$pqr=456 I need to replace $$pqr from 456 to a new value which will be present in a variable to me. I am not aware of sed and awk functionality. Can somebody please show me how to replace this... (6 Replies)
Discussion started by: lifzgud
6 Replies

5. UNIX for Dummies Questions & Answers

Write to file using tail -f through a pipe to grep

Hi -- I'm looking to write to a file after piping output from tail -f through to grep: #write to a file for all lines with "searchtext" within in error_log: Expand|Select|Wrap|Line Numbers tail -f /var/error_log | grep searchtext > output.txt The above command... (2 Replies)
Discussion started by: ndedhia1
2 Replies

6. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

7. Shell Programming and Scripting

Check for Pattern if exists write to file

Hi ! All I just want to search and write to new file if pattern is found in text file following are my text files by which I want to search Month and last column number my text file1 15-Jan-2011 25 ARTS 1255 125 125 178 198 15-Jan-2011 25 ARTS 1255 125 125 178 198 15-Jan-2011 25... (3 Replies)
Discussion started by: nex_asp
3 Replies

8. Shell Programming and Scripting

Search pattern and write line into another file

Hi, I have a file which contains the below details.. My requirement is to fetch all the lines which are starting with "ABC_XY_" into 1 file and rest of the lines (not starting with "ABC_XY_") into another file. Could you please help with what command needs to be used? file1.txt ----------... (12 Replies)
Discussion started by: satyaatcgi
12 Replies

9. Shell Programming and Scripting

Piping through grep/awk prevents file write

So, this is weird... I'm running this command: iotop -o -P -k -bt -d 5 I'd like to save the output relelvant to rsyslogd to a file, so I do this: iotop -o -P -k -bt -d 5 | grep rsyslogd >> /var/log/rsyslogd Nothing is written to the file! I can write the full output to the file: ... (2 Replies)
Discussion started by: treesloth
2 Replies

10. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies
LOCKTEST(1)							  [FIXME: manual]						       LOCKTEST(1)

NAME
locktest - Find differences in locking between two SMB servers SYNOPSIS
locktest {//server1/share1} {//server2/share2} [-U user%pass] [-U user%pass] [-s seed] [-o numops] [-a] [-O] [-E] [-Z] [-R range] [-B base] [-M min] DESCRIPTION
locktest is a utility for detecting differences in behaviour in locking between SMB servers. It will run a random set of locking operations against //server1/share1 and then the same random set against //server2/share2 and display the differences in the responses it gets. This utility is used by the Samba team to find differences in behaviour between Samba and Windows servers. OPTIONS
-U user%pass Specify the user and password to use when logging on on the shares. This parameter can be specified twice (once for the first server, once for the second). -s seed Seed the random number generator with the specified value. -o numops Set the number of operations to perform. -a Print the operations that are performed. -A Backtrack to find minimal number of operations required to make the response to a certain call differ. -O Enable oplocks. -u Hide unlock fails. -E enable exact error code checking -Z enable the zero/zero lock -R range set lock range -B base set lock base -M min set min lock length -k Use kerberos VERSION
This man page is correct for version 4.0 of the Samba suite. SEE ALSO
Samba AUTHOR
This utility is part of the Samba[1] suite, which is developed by the global Samba Team[2]. locktest was written by Andrew Tridgell. This manpage was written by Jelmer Vernooij. NOTES
1. Samba http://www.samba.org/ 2. Samba Team http://www.samba.org/samba/team/ [FIXME: source] 04/16/2014 LOCKTEST(1)
All times are GMT -4. The time now is 09:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy