Sponsored Content
Top Forums Shell Programming and Scripting Find and replace value using a key from other file Post 302726253 by jiam912 on Sunday 4th of November 2012 06:45:23 AM
Old 11-04-2012
Dear ctsgnb

Thansk a lot for four help,, and soory for the uppercase letters,, I didn't notice that..

Regards

---------- Post updated at 06:45 AM ---------- Previous update was at 01:52 AM ----------

Dear ctsgnb

the code is working perfect, as you say I got all the substitutions in the file .new..
But please can you advise me why , when I run the script change2run
give me this msg.

> change2run
Code:
awk: change2run:3: awk '{F=$1;a[F];e=(F~/sps$/)?"  ":z;s=$2"   "$3;p=$4;r=$5;
awk: change2run:3:     ^ invalid char ''' in expression


The code is as following
Code:
awk -f change2run

awk '{F=$1;a[F];e=(F~/sps$/)?"  ":z;s=$2"   "$3;p=$4;r=$5;
print "s/" s e p "/" s e r "/" >> F".sed"
}END{
for(i in a){print "sed -f "i".sed "i " >>"i".new">>"change2run"}
}' datatochange.txt

and I notice that in the file datatochange.txt..
there is many new enters

Code:
sed -f sw1166g.xps.sed sw1166g.xps >>sw1166g.xps.new
sed -f sw1163g.sps.sed sw1163g.sps >>sw1163g.sps.new
sed -f sw1152g.xps.sed sw1152g.xps >>sw1152g.xps.new
sed -f sw1132g.sps.sed sw1132g.sps >>sw1132g.sps.new
sed -f sw1129g.sps.sed sw1129g.sps >>sw1129g.sps.new
sed -f sw1153g.sps.sed sw1153g.sps >>sw1153g.sps.new
sed -f sw1136g.sps.sed sw1136g.sps >>sw1136g.sps.new
sed -f sw1148g.sps.sed sw1148g.sps >>sw1148g.sps.new
sed -f sw1137g.xps.sed sw1137g.xps >>sw1137g.xps.new
sed -f sw1144g.xps.sed sw1144g.xps >>sw1144g.xps.new
sed -f sw1130g.xps.sed sw1130g.xps >>sw1130g.xps.new
sed -f sw1131g.sps.sed sw1131g.sps >>sw1131g.sps.new
sed -f sw1163g.xps.sed sw1163g.xps >>sw1163g.xps.new
sed -f sw1132g.xps.sed sw1132g.xps >>sw1132g.xps.new
sed -f sw1129g.xps.sed sw1129g.xps >>sw1129g.xps.new
sed -f sw1164g.sps.sed sw1164g.sps >>sw1164g.sps.new
sed -f sw1153g.xps.sed sw1153g.xps >>sw1153g.xps.new
sed -f sw1147g.sps.sed sw1147g.sps >>sw1147g.sps.new
sed -f sw1136g.xps.sed sw1136g.xps >>sw1136g.xps.new
sed -f sw1148g.xps.sed sw1148g.xps >>sw1148g.xps.new
sed -f sw1166g.sps.sed sw1166g.sps >>sw1166g.sps.new
sed -f sw1152g.sps.sed sw1152g.sps >>sw1152g.sps.new
sed -f sw1131g.xps.sed sw1131g.xps >>sw1131g.xps.new
sed -f sw1137g.sps.sed sw1137g.sps >>sw1137g.sps.new
sed -f sw1164g.xps.sed sw1164g.xps >>sw1164g.xps.new
sed -f sw1147g.xps.sed sw1147g.xps >>sw1147g.xps.new
sed -f sw1144g.sps.sed sw1144g.sps >>sw1144g.sps.new
sed -f sw1130g.sps.sed sw1130g.sps >>sw1130g.sps.new

Thanks for your cooperation
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find replace within a file?

I build several files by using the cut command to grab select fields(columns) from a really bid csv file. Each file is one column of data. I then put them together using paste command. Here is the code built in tcsh: cut -d , -f 1 some.csv > 1.csv cut -d , -f 10 some.csv > 10.csv paste 1.csv... (2 Replies)
Discussion started by: yankee428
2 Replies

2. Shell Programming and Scripting

how to replace a text inside a file based on a xml key

<c-param> <param-name>Number</param-name> <param-value>22</param-value> <description>my house number</description> </c-param> <c-param> <param-name>Address</param-name> ... (4 Replies)
Discussion started by: reldb
4 Replies

3. Shell Programming and Scripting

Find and replace in a file

Hi everyone, I am new to the world of shell script programming. I have a file named Fnd1.txt which has the contents as below. I need to replace the \t with the tab space. Can any one help me to write a perl scipt for this. USA45V1\tG\t341029 USAV1T1\tG\t450545 USAREJ1\tG\t572645... (5 Replies)
Discussion started by: vinay123
5 Replies

4. Shell Programming and Scripting

Find and replace in a gz file

Is there a way to do a find and replace in a .gz file in a single script ? I can always unzip, find and replace and then zip it again but would hate to do this everytime. Thanks ! Vivek (1 Reply)
Discussion started by: vashah
1 Replies

5. Shell Programming and Scripting

C Shell problem: using a key from one file to find data in another

I've never written scripts (just switched from Ada to C++). I have a book that's over my head and a few examples, other then that I'm floundering. Everything here at work is being done in C Shell. None of the C++ programmers are experienced in shell scripting. I have a data file with the... (2 Replies)
Discussion started by: bassmaster
2 Replies

6. Shell Programming and Scripting

Find and Replace in File

Legends, I have a file /tmp/list.txt I want to find "/bin/" and replace it with "/log/" I tried the follwoing but no luck Sandy: /tmp> perl -pi -e 's/\/bin\/\/log\/' /tmp/list.txt >> /tmp/try Substitution pattern not terminated at -e line 1. AND, Sandy: /tmp> perl -pi -e... (2 Replies)
Discussion started by: sdosanjh
2 Replies

7. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

8. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

9. Shell Programming and Scripting

Find Key and replace value

Hi, I am new to shell scripting. I have a config file where key and value is stored as below. In my shell script, I want to look for Test ID in the config file and replace the value 1 with another value stored in a variable. How would I do that ? <Config Key="Test ID" Value="1"/> I... (6 Replies)
Discussion started by: Vishnuvardhanh
6 Replies

10. UNIX for Beginners Questions & Answers

Need to find and replace in a file

Hi All, I am having below sample data in a file. I need to find all the line form this file with word ABC and i need to replace the characters at position 120 which is "CO:BOGFDUI"(30chars) in the lines with blank space. I have tried using grep to find the word with ABC (grep ABC filename),... (3 Replies)
Discussion started by: abhi_123
3 Replies
File::Find::Rule::Perl(3)				User Contributed Perl Documentation				 File::Find::Rule::Perl(3)

NAME
File::Find::Rule::Perl - Common rules for searching for Perl things SYNOPSIS
use File::Find::Rule (); use File::Find::Rule::Perl (); # Find all Perl files smaller than 10k my @files = File::Find::Rule->perl_file ->size('<10Ki') ->in('dir'); # Locate all the modules that PAUSE will index my @mod = File::Find::Rule->no_index ->perl_module ->in('My-Distribution'); DESCRIPTION
I write a lot of things that muck with Perl files. And it always annoyed me that finding "perl files" requires a moderately complex File::Find::Rule pattern. File::Find::Rule::Perl provides methods for finding various types Perl-related files, or replicating search queries run on a distribution in various parts of the CPAN ecosystem. METHODS
perl_module The "perl_module" rule locates perl modules. That is, files that are named "*.pm". This rule is equivalent to "->"file->name( '*.pm' )> and is included primarily for completeness. perl_test The "perl_test" rule locates perl test scripts. That is, files that are named "*.t". This rule is equivalent to "->"file->name( '*.t' )> and is included primarily for completeness. perl_installer The "perl_installer" rule locates perl distribution installers. That is, it locates "Makefile.PL" and "Build.PL" files. perl_script The "perl_script" rule locates perl scripts. This is any file that ends in .pl, or any files without extensions that have a perl "hash-bang" line. perl_file The "perl_file" rule locates all files containing Perl code. This includes all the files matching the above "perl_module", "perl_test", "perl_installer" and "perl_script" rules. no_index # Provide the rules directly $rule->no_index( directory => [ 'inc', 't', 'examples' ], file => [ 'Foo.pm', 'lib/Foo.pm' ], ); # Provide a META.yml to use $rule->no_index( 'META.yml' ); # Provide a dist root directory to look for a META.yml in $rule->no_index( 'My-Distribution' ); # Automatically pick up a META.yml from the target directory $rule->no_index->in( 'My-Distribution' ); The "no_index" method applies a set of rules as per the no_index section in a "META.yml" file. SUPPORT
Bugs should always be submitted via the CPAN bug tracker <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Find-Rule-Perl> For other issues, contact the maintainer AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
<http://ali.as/>, File::Find::Rule, File::Find::Rule::PPI COPYRIGHT
Copyright 2006 - 2012 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.16.3 2012-10-31 File::Find::Rule::Perl(3)
All times are GMT -4. The time now is 09:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy