Sponsored Content
Top Forums Shell Programming and Scripting Shell Script to replace tokens in multiple files Post 302250517 by cbo0485 on Thursday 23rd of October 2008 02:34:45 PM
Old 10-23-2008
Okay, I have about, 8 variables(now that I think about it, variable isn't the best name for them. More just tags that I have created in the following format to make it easy to replace them manually, which I am now trying to do with a script). All named in this format


@tag1@
@tag2@
@tag3@
etc
.
.
.
Now the text inside the @..@ tag doesn't follow the naming convention of tag1.2.3.4.... etc, but it was just easier to use that on here.


The file names that hold these tags are as follows:

startTestABC
stopTestABC
deleteABC
rotateABC

A little more information would be that those ABC scripts all set some variable equal to the tag, ie

TEST_NAME="@tag3@"
ANOT_VAR="@tag4@"

That way, when I run the script I can replace all the @...@ tags with what I need, and then the bottom of the script calls everything by the constant variable names.

I was thinking either the script has a header that I could vi it and change it b/c this script will be used over and over with different values for the tags each time. So, either a header section, or even an interactive script where it asks for the values, stores them, then uses those to run the replace command in each script.

Output is obviously the updated ABC script. It doesn't even need to create the new files, all it has to do is modify the existing script, b/c I have my directory which holds these scripts, and then when I use them I always have to move them somewhere else, and then run the replace script from the new directory.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and Replace in multiple files (Shell script)

hi guys, Suppose you have 100 files in a folder and you want to replace all occurances of a word say "ABCD" in those files with "DCBA", how would you do it ??? jatin (13 Replies)
Discussion started by: jatins_s
13 Replies

2. Shell Programming and Scripting

Shell script to parse/split input string and display the tokens

Hi, How do I parse/split lines (strings) read from a file and display the individual tokens in a shell script? Given that the length of individual lines is not constant and number of tokens in each line is also not constant. The input file could be as below: ... (3 Replies)
Discussion started by: yajaykumar
3 Replies

3. Shell Programming and Scripting

shell script to find and replace string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (11 Replies)
Discussion started by: pharos467
11 Replies

4. Shell Programming and Scripting

Complex Search/Replace Multiple Files Script Needed

I have a rather complicated search and replace I need to do among several dozen files and over a hundred occurrences. My site is written in PHP and throughout the old code, you will find things like die("Operation Aborted due to....."); For my new design skins for the site, I need to get... (2 Replies)
Discussion started by: UCCCC
2 Replies

5. Shell Programming and Scripting

Strip log file with multiple tokens

I have app log files that need to be cleansed for readability, and my sed skills are not adequate. Each line has a long multi-segment header, which I am trying to remove, example below: : 2010.05.26 20:38:00.640--DatabaseSessionImpl(21447570)--Connection(26209441)--Thread(Thread)--SELECT... (4 Replies)
Discussion started by: migurus
4 Replies

6. Shell Programming and Scripting

Need tokens in shell script

Hi All, Im writing a shell script in which I want to get the folder names in one folder to be used in for loop. I have used: packsName=$(cd ~/packs/Acquisitions; ls -l| awk '{print $9}') echo $packsName o/p: opt temp user1 user2 ie. Im getting the output as a string. But I want... (3 Replies)
Discussion started by: AB10
3 Replies

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

8. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

9. Shell Programming and Scripting

Getting error -: more tokens expected in shell script

Hi can someone help me to resolve the error for this condition if ] && ]; then i am passing the values $k and $kkm i am getting the error like "-: more tokens expected" Thanks in Advance (5 Replies)
Discussion started by: makigate
5 Replies

10. Shell Programming and Scripting

Script to replace stings in multiple text files

Good Evening Folks - Happy Friday! I have a need to replace a certain string in all .csv files from "0.00" to "#Missing" in my /app/hyp_app/files directory. Does anyone have a script they use regularly that's rather quick in performance? My files are rather large so I'm looking for a... (5 Replies)
Discussion started by: SIMMS7400
5 Replies
BP_META_GFF(1p) 					User Contributed Perl Documentation					   BP_META_GFF(1p)

NAME
bp_meta_gff.pl - Get/set Bio::DB::GFF meta-data SYNOPSIS
# set the following meta data values % bp_meta_gff.pl -d testdb tag1=value1 tag2=value2 # get the indicated meta data value % bp_meta_gff.pl -d testdb tag1 tag2 DESCRIPTION
This script gets or sets metadata in a Bio::DB::GFF database. Not all adaptors support this operation! To set a series of tags, pass a set of tag=value pairs to the script. To get the contents of a series of tags, pass the bare tag names. The output from the get operation will be an easily parseable set of tag=value pairs, one per line. COMMAND-LINE OPTIONS Command-line options can be abbreviated to single-letter options. e.g. -d instead of --database. --database <dsn> Mysql database name (default dbi:mysql:test) --adaptor <adaptor> Mysql adaptor (default dbi::mysqlopt) --user <user> Username for mysql authentication --pass <password> Password for mysql authentication SEE ALSO
Bio::DB::GFF AUTHOR
Lincoln Stein, lstein@cshl.org Copyright (c) 2002 Cold Spring Harbor Laboratory This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See DISCLAIMER.txt for disclaimers of warranty. perl v5.14.2 2012-03-02 BP_META_GFF(1p)
All times are GMT -4. The time now is 02:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy