Sponsored Content
Top Forums Shell Programming and Scripting Shell script to replace strings to and from a file Post 302365327 by Scott on Monday 26th of October 2009 04:45:14 PM
Old 10-26-2009
Code:
/tmp # cat Test
awk '
  NR == FNR { A[$1] = $2; next }
  { print $1, A[$2], $3 }
' pattern source

./Test
asasa A adfhsdfsdfasdf
zxzxzx B dsadasdasdsadasd
kjjkjkjk C asdsadsadsadsadsad
vxcvxcvx A qwewqewqeqweqwe

 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how to replace a line in a file using shell script

I have a property file in which the DB name is specified and when i run my servers they will point to the DB specified in that property file. Now i'm gonna write a script which will start all the services. But before that i just want to dynamically change the DB name in that property file by... (3 Replies)
Discussion started by: cs_sakthi
3 Replies

2. Shell Programming and Scripting

replace strings in a file

Hi I want to change the following passwd: files nis group: files nis in /etc/nsswitch.conf to be passwd: files compat group: files compat I tried cp -p nsswitch.conf nsswitch.conf.old (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

3. Shell Programming and Scripting

Replace multiple strings in a file.

Hello Freinds, Hope, you all are doing well. I have to replace the static strings from one file (File 1) with the dynamic strings from the another file (File2). I've written a shell script for this.Below is the contents. while read line do field=`echo $line | awk '{print $1}'` ... (9 Replies)
Discussion started by: singh.chandan18
9 Replies

4. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

5. Shell Programming and Scripting

Replace the strings in file

Hello members, I been following this forums since very long time. I need to do one job. In my script I am evaluating one variable, lets say n=100. Now i have xml file inside which i need to replace the numbers in the desired lines with the evaluated number(n) +1. For example let's say... (4 Replies)
Discussion started by: mailtosaiki
4 Replies

6. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

7. Shell Programming and Scripting

Replace multiple strings of a file

Hi, I have an array variable "arr" that reads string from a file "vari.txt". Thus, the array will be of variable length depending how many entries are present in "vari.txt" I use a for loop to traverse through the array. vari.txt (in this sample we have 2 entries, but it can have more... (5 Replies)
Discussion started by: mohtashims
5 Replies

8. Red Hat

How to replace Ip address in .xml file through shell script?

I have one .xml file. which contains the following line. <ParamString StringId="PortAddress" StringValue="172.27.166.170" /> <ParamString StringId="PortAddress" StringValue="172.27.166.171" /> <ParamString StringId="PortAddress" StringValue="172.27.166.202" /> <ParamString... (9 Replies)
Discussion started by: Anjan Ganguly
9 Replies

9. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies
Test::TempDir::Factory(3pm)				User Contributed Perl Documentation			       Test::TempDir::Factory(3pm)

NAME
Test::TempDir::Factory - A factory for creating Test::TempDir::Handle objects. SYNOPSIS
my $f = Test::TempDir::Factory->new; my $d = $f->create; $d->empty; # ... $d->cleanup DESCRIPTION
This class creates Test::TempDir::Handle objects with the right "dir" parameter, taking care of obtaining locks, creating directories, and handling fallback logic. ATTRIBUTES
lock Whether or not to enable locking. Defaults to true. lock_opts A hash reference to pass to File::NFSLock. Defaults to "NONBLOCKING" lock_attempts How many times to try to create and lock a dir. Defaults to 2. dir_name The directory under "t_dir" to use. Defaults to "tmp" t_dir Defaults to "t" use_subdir Whether to always use a temporary subdirectory under the temporary root. This means that with a "success" cleanup policy all failures are retained. When disabled, "t/tmp" will be used directly as "temp_root". Defaults to true. subdir_template The template to pass to "tempdir". Defaults to "File::Temp::TEMPXXX". handle_class Defaults to Test::TempDir::Handle. verbose Whether or not to "carp" diagnostics when falling back. If you subclass this factory and add a "logger" method a la MooseX::Logger then this parameter is ignored and all messages will be "warn"ed on the logger. METHODS
create Create a Test::TempDir::Handle object with a proper "dir" attribute. perl v5.10.0 2009-08-10 Test::TempDir::Factory(3pm)
All times are GMT -4. The time now is 03:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy