Sponsored Content
Top Forums Shell Programming and Scripting Need to replace one string, in a file, with another string from a different file ... Post 302352781 by know d unknown on Sunday 13th of September 2009 10:23:04 AM
Old 09-13-2009
thx for pointing out ripat...
the following code will work fine:

awk -F":" 'NR==FNR{a[$1]=$0; next} NR!=FNR{if(a[$1])print a[$1]; else print $0}' shadow2 shadow1
David:$1$FbP0lc8N$MIJ8outnkYyBedIYK7TJ6.:14500:0:90:7:::
sarvani:$1$0wPwj2dB$GSHkbM9kcPZkGPTdKfZJP1:14293:0:90:7:::
stuart:$1$sPgpLdir$b9qcdXKeJ78zaZ2tpJuuA/:13924:0:90:7:::

check if this works fine
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How To Replace A String In File With A String Containing Windows File Path

Hi, I have a file with the following contents # Lines that start with a # are comments. # # Calling TOAD like this will perform a comparison from command line : # # "C:\Program Files\Quest Software\Toad for Oracle 9.6\toad.exe" -c... (2 Replies)
Discussion started by: rajan_san
2 Replies

2. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

3. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

4. UNIX for Dummies Questions & Answers

Search a string in the file and then replace another string after that position

Hi I am looking for a particular string in a file.If the string exists, then I want to replace another string with some other text.Once replaced, search for the same text after that character position in the file. :wall: E.g: Actual File content: Hello Name: Nitin Raj Welcome to Unix... (4 Replies)
Discussion started by: dashing201
4 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

7. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

8. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

9. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

10. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies
File::chdir(3pm)					User Contributed Perl Documentation					  File::chdir(3pm)

NAME
File::chdir - a more sensible way to change directories VERSION
version 0.1006 SYNOPSIS
use File::chdir; $CWD = "/foo/bar"; # now in /foo/bar { local $CWD = "/moo/baz"; # now in /moo/baz ... } # still in /foo/bar! DESCRIPTION
Perl's "chdir()" has the unfortunate problem of being very, very, very global. If any part of your program calls "chdir()" or if any library you use calls "chdir()", it changes the current working directory for the whole program. This sucks. File::chdir gives you an alternative, $CWD and @CWD. These two variables combine all the power of "chdir()", File::Spec and Cwd. $CWD Use the $CWD variable instead of "chdir()" and Cwd. use File::chdir; $CWD = $dir; # just like chdir($dir)! print $CWD; # prints the current working directory It can be localized, and it does the right thing. $CWD = "/foo"; # it's /foo out here. { local $CWD = "/bar"; # /bar in here } # still /foo out here! $CWD always returns the absolute path in the native form for the operating system. $CWD and normal "chdir()" work together just fine. @CWD @CWD represents the current working directory as an array, each directory in the path is an element of the array. This can often make the directory easier to manipulate, and you don't have to fumble with "File::Spec->splitpath" and "File::Spec->catdir" to make portable code. # Similar to chdir("/usr/local/src/perl") @CWD = qw(usr local src perl); pop, push, shift, unshift and splice all work. pop and push are probably the most useful. pop @CWD; # same as chdir(File::Spec->updir) push @CWD, 'some_dir' # same as chdir('some_dir') @CWD and $CWD both work fine together. NOTE Due to a perl bug you can't localize @CWD. See "BUGS and" for a work around. EXAMPLES
(We omit the "use File::chdir" from these examples for terseness) Here's $CWD instead of "chdir()": $CWD = 'foo'; # chdir('foo') and now instead of Cwd. print $CWD; # use Cwd; print Cwd::abs_path you can even do zsh style "cd foo bar" $CWD = '/usr/local/foo'; $CWD =~ s/usr/var/; if you want to localize that, make sure you get the parens right { (local $CWD) =~ s/usr/var/; ... } It's most useful for writing polite subroutines which don't leave the program in some strange directory: sub foo { local $CWD = 'some/other/dir'; ...do your work... } which is much simpler than the equivalent: sub foo { use Cwd; my $orig_dir = Cwd::abs_path; chdir('some/other/dir'); ...do your work... chdir($orig_dir); } @CWD comes in handy when you want to start moving up and down the directory hierarchy in a cross-platform manner without having to use File::Spec. pop @CWD; # chdir(File::Spec->updir); push @CWD, 'some', 'dir' # chdir(File::Spec->catdir(qw(some dir))); You can easily change your parent directory: # chdir from /some/dir/bar/moo to /some/dir/foo/moo $CWD[-2] = 'foo'; CAVEATS
Assigning to @CWD calls "chdir()" for each element @CWD = qw/a b c d/; Internally, Perl clears @CWD and assigns each element in turn. Thus, this code above will do this: chdir 'a'; chdir 'a/b'; chdir 'a/b/c'; chdir 'a/b/c/d'; Generally, avoid assigning to @CWD and just use push and pop instead. "local @CWD" does not work. "local @CWD>" will not localize @CWD. This is a bug in Perl, you can't localize tied arrays. As a work around localizing $CWD will effectively localize @CWD. { local $CWD; pop @CWD; ... } Volumes not handled There is currently no way to change the current volume via File::chdir. NOTES
$CWD returns the current directory using native path separators, i.e. on Win32. This ensures that $CWD will compare correctly with directories created using File::Spec. For example: my $working_dir = File::Spec->catdir( $CWD, "foo" ); $CWD = $working_dir; doing_stuff_might_chdir(); is( $CWD, $working_dir, "back to original working_dir?" ); Deleting the last item of @CWD will act like a pop. Deleting from the middle will throw an exception. delete @CWD[-1]; # OK delete @CWD[-2]; # Dies What should %CWD do? Something with volumes? # chdir to C:Program FilesSierraHalf Life ? $CWD{C} = '\Program Files\Sierra\Half Life'; DIAGNOSTICS
If an error is encountered when changing $CWD or @CWD, one of the following exceptions will be thrown: o Can't delete except at the end of @CWD o Failed to change directory to '$dir' HISTORY
Michael wanted "local chdir" to work. p5p didn't. But it wasn't over! Was it over when the Germans bombed Pearl Harbor? Hell, no! Abigail and/or Bryan Warnock suggested the $CWD thing (Michael forgets which). They were right. The "chdir()" override was eliminated in 0.04. David became co-maintainer with 0.06_01 to fix some chronic Win32 path bugs. As of 0.08, if changing $CWD or @CWD fails to change the directory, an error will be thrown. SEE ALSO
File::pushd, File::Spec, Cwd, "chdir" in perlfunc, "Animal House" <http://www.imdb.com/title/tt0077975/quotes> SUPPORT
Bugs / Feature Requests Please report any bugs or feature requests by email to "bug-file-chdir at rt.cpan.org", or through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=File-chdir>. You will be automatically notified of any progress on the request by the system. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. <https://github.com/dagolden/file-chdir> git clone https://github.com/dagolden/file-chdir.git AUTHORS
o David A Golden <dagolden@cpan.org> o Michael G Schwern <schwern@pobox.com> (original author) COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Michael G Schwern and David A Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.10.1 2011-11-02 File::chdir(3pm)
All times are GMT -4. The time now is 09:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy