Sponsored Content
Top Forums Shell Programming and Scripting Search & Replace: Multiple Strings / Multiple Files Post 302716705 by rdrtx1 on Tuesday 16th of October 2012 07:24:26 PM
Old 10-16-2012
If working with files that are ":" field delimited:

Code:
 
pwds file (pwd:replace pwd):
s/1zg6/2RWAUY,2/lR:@#xyyyy$@#!$@#
JQy74TuvHyqMo:@#$@#!xxxxx$@#
32oVGmESDPBLk:@#$@234234wa#!$@#
VkrDf0FVYbg7.,2/cW:@#$sss@#!$@#
hWTRS2IF9EOQc,2/mW:@#$@aaaa#!$@#
OrfQo.EYJo9q6:@#$35345@#!$@#
2oK927ArLTgnY,B.mW:@#$@23234#!$@#

somefile:
Code:
user:s/1zg6/2RWAUY,2/lR:user:::::
user:JQy74TuvHyqMo:user:::::
user:32oVGmESDPBLk:1162:user:::::
user:VkrDf0FVYbg7.,2/cW:user:::::
user:hWTRS2IF9EOQc,2/mW:user:::::
user:OrfQo.EYJo9q6:user:::::
user:2oK927ArLTgnY,B.mW:user:::::


using awk:
Code:
 
awk -F: '
NR==FNR {pw[$1]=$2; next;}
{ FS=":";
  for (i=1; i<=NF; i++) {
    if (length(pw[$i])>0) $i=pw[$i];
  }
  print;
}
' OFS=: pwds somefile

output:
Code:
 
user:@#xyyyy$@#!$@#:user:::::
user:@#$@#!xxxxx$@#:user:::::
user:@#$@234234wa#!$@#:1162:user:::::
user:@#$sss@#!$@#:user:::::
user:@#$@aaaa#!$@#:user:::::
user:@#$35345@#!$@#:user:::::
user:@#$@23234#!$@#:user:::::

This User Gave Thanks to rdrtx1 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

2. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

Hi, I have a folder which contains multiple config.xml files and one input file, Please see the below format. Config Files format looks like :- Code: <application name="SAMPLE-ARCHIVE"> <NVPairs name="Global Variables"> <NameValuePair> ... (0 Replies)
Discussion started by: haiksuresh
0 Replies

3. Shell Programming and Scripting

Global search and replace across multiple files

Hi all I'm in need of a command which can replace a specified string with another string - across multiple files within multiple sub-directories (I intend to run it from / ) I've used the following to get a list of the files: find . | xargs grep <string1> But that's as far as I've got.... (7 Replies)
Discussion started by: huskie69
7 Replies

4. UNIX for Dummies Questions & Answers

how to find and replace strings in multiple files

Hi All, Iam new to unix, I need to find string and replace it in the file name. Like text_123_0.txt,text_123_1.txt,text_123_2.txt. I need to search 123 and replace it with 234 . Is there any unix command to replace them in single command since i have 5 directories. So i need to go each and every... (0 Replies)
Discussion started by: etldeveloper
0 Replies

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

6. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

7. Shell Programming and Scripting

perl: search replace in multiple files

When I use special characters the command to replace multiple files with a string pattern does nt work. ---------- Post updated at 12:33 PM ---------- Previous update was at 11:38 AM ---------- This works perl -pi -e 's/100/test/g' * This does nt work perl -pi -e 's... (1 Reply)
Discussion started by: w020637
1 Replies

8. Shell Programming and Scripting

Search and Replace in multiple files

Hello, I have hundreds of files in which I need to change email address. Here is what I am trying to do: 1. All text files are in a directory "a" 2. In the text file, I want to replace email address for preparer. All these lines start with {{PreparerEmail and end with }}. The email... (3 Replies)
Discussion started by: cartrider
3 Replies

9. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

I have a environment property file which contains: Input file: value1 = url1 value2 = url2 value3 = url3 and so on. I need to search all *.xml files under directory for value1 and replace it with url1. Same thing I have to do for all values mentioned in input file. I need script in unix bash... (7 Replies)
Discussion started by: Shamkamde
7 Replies

10. Shell Programming and Scripting

Search/Replace in multiple files recursively

Hi there, I am using AIX and trying to search and replace a string with another string in multiple files in different directories. I wanted to search replace in steps so I don't change all of the instance anywhere in the server at once, minimizing impact. STEP 1: -------- I first searched... (5 Replies)
Discussion started by: zaino22
5 Replies
packages(3erl)						     Erlang Module Definition						    packages(3erl)

NAME
packages - Packages in Erlang DESCRIPTION
Warning: Packages has since it was introduced more than 5 years ago been an experimental feature. Use it at your own risk, we do not actively main- tain and develop this feature. It might however be supported some day. In spite of this packages work quite well, but there are some known issues in tools and other parts where packages don't work well. Introduction Packages are simply namespaces for modules. All old Erlang modules automatically belong to the top level ("empty-string") namespace, and do not need any changes. The full name of a packaged module is written as e.g. " fee.fie.foe.foo ", i.e., as atoms separated by periods, where the package name is the part up to but not including the last period; in this case " fee.fie.foe ". A more concrete example is the module erl.lang.term , which is in the package erl.lang . Package names can have any number of segments, as in erl.lang.list.sort . The atoms in the name can be quoted, as in foo.'Bar'.baz , or even the whole name, as in 'foo.bar.baz' but the concatenation of atoms and periods must not contain two consecu- tive period characters or end with a period, as in 'foo..bar' , foo.'.bar' , or foo.'bar.' . The periods must not be followed by white- space. The code loader maps module names onto the file system directory structure. E.g., the module erl.lang.term corresponds to a file .../erl/lang/term.beam in the search path. Note that the name of the actual object file corresponds to the last part only of the full mod- ule name. (Thus, old existing modules such as lists simply map to .../lists.beam , exactly as before.) A packaged module in a file " foo/bar/fred.erl " is declared as: -module(foo.bar.fred). This can be compiled and loaded from the Erlang shell using c(fred) , if your current directory is the same as that of the file. The object file will be named fred.beam . The Erlang search path works exactly as before, except that the package segments will be appended to each directory in the path in order to find the file. E.g., assume the path is ["/usr/lib/erl", "/usr/local/lib/otp/legacy/ebin", "/home/barney/erl"] . Then, the code for a mod- ule named foo.bar.fred will be searched for first as "/usr/lib/erl/foo/bar/fred.beam" , then "/usr/local/lib/otp/legacy/ebin/foo/bar/fred.beam" and lastly "/home/barney/erl/foo/bar/fred.beam" . A module like lists , which is in the top-level package, will be looked for as "/usr/lib/erl/lists.beam" , "/usr/local/lib/otp/legacy/ebin/lists.beam" and "/home/bar- ney/erl/lists.beam" . Programming Normally, if a call is made from one module to another, it is assumed that the called module belongs to the same package as the source mod- ule. The compiler automatically expands such calls. E.g., in: -module(foo.bar.m1). -export([f/1]). f(X) -> m2:g(X). m2:g(X) becomes a call to foo.bar.m2 If this is not what was intended, the call can be written explicitly, as in -module(foo.bar.m1). -export([f/1]). f(X) -> fee.fie.foe.m2:g(X). Because the called module is given with an explicit package name, no expansion is done in this case. If a module from another package is used repeatedly in a module, an import declaration can make life easier: -module(foo.bar.m1). -export([f/1, g/1]). -import(fee.fie.foe.m2). f(X) -> m2:g(X). g(X) -> m2:h(X). will make the calls to m2 refer to fee.fie.foe.m2 . More generally, a declaration -import(Package.Module). will cause calls to Module to be expanded to Package.Module . Old-style function imports work as normal (but full module names must be used); e.g.: -import(fee.fie.foe.m2, [g/1, h/1]). however, it is probably better to avoid this form of import altogether in new code, since it makes it hard to see what calls are really "remote". If it is necessary to call a module in the top-level package from within a named package, the module name can be written either with an initial period as in e.g. " .lists ", or with an empty initial atom, as in " ''.lists ". However, the best way is to use an import declara- tion - this is most obvious to the eye, and makes sure we don't forget adding a period somewhere: -module(foo.bar.fred). -export([f/1]). -import(lists). f(X) -> lists:reverse(X). The dot-syntax for module names can be used in any expression. All segments must be constant atoms, and the result must be a well-formed package/module name. E.g.: spawn(foo.bar.fred, f, [X]) is equivalent to spawn('foo.bar.fred', f, [X]) . The Erlang Shell The shell also automatically expands remote calls, however currently no expansions are made by default. The user can change the behaviour by using the import/1 shell command (or its abbreviation use/1 ). E.g.: 1> import(foo.bar.m). ok 2> m:f(). will evaluate foo.bar.m:f() . If a new import is made of the same name, this overrides any previous import. (It is likely that in the future, some system packages will be pre-imported.) In addition, the shell command import_all/1 (and its alias use_all/1 ) imports all modules currently found in the path for a given package name. E.g., assuming the files " .../foo/bar/fred.beam ", " .../foo/bar/barney.beam " and " .../foo/bar/bambam.beam " can be found from our current path, 1> import_all(foo.bar). will make fred , barney and bambam expand to foo.bar.fred , foo.bar.barney and foo.bar.bambam , respectively. Note: The compiler does not have an "import all" directive, for the reason that Erlang has no compile time type checking. E.g. if the wrong search path is used at compile time, a call m:f(...) could be expanded to foo.bar.m:f(...) without any warning, instead of the intended frob.ozz.m:f(...) , if package foo.bar happens to be found first in the path. Explicitly declaring each use of a module makes for safe code. EXPORTS
no functions exported Ericsson AB kernel 2.14.3 packages(3erl)
All times are GMT -4. The time now is 06:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy