Sponsored Content
Top Forums Shell Programming and Scripting Scripting change of text in another file Post 302341618 by vwgtiturbo on Thursday 6th of August 2009 09:35:31 AM
Old 08-06-2009
Scripting change of text in another file

Hello, I am pretty new to UNIX/bash scripting, so this question may seem obvious. My experience is simply stringing commands together in a script, maybe doing some if/then testing and such, so I haven't gotten into anything too heavy...

I have a shell script that I use as a template to create backup scripts for certain directories. These scripts are essentially the same, with the exception of the value of some variables. Other than that, they are identical. So, it is easy enough to simply make copies of this template, then manually go in and change the variable names (I make separate scripts for each directory, as some are deemed more important, so I want them backed up via cron more frequently). To make the copies, I have simply done:

for copy in dir1 dir2 dir3; do
cp template.sh $copy.sh
done

It is crude yes, but like I said, I am inexperienced (I'm trying though!). I was wondering what I would need in order to change the variable values as well, so I can script it all. That way, I could edit the template file, then run one script and it would produce the copies and change their variable values. I have done some reading on 'awk' and 'sed', but am not sure which I need (or if I need both)

Just a nudge is all I need... No need to do it for me! Thanks for any insight.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell scripting adding text to top of file

Hi this is quite simple i am sure but without using awk or sed i need to add text to the top of a file this is what i have got so far #!bin/bash echo "Add text to top of file" read line echo $line >> file1 This adds the text to the bottom of the file can some1 please help cheers (7 Replies)
Discussion started by: meadhere
7 Replies

2. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

3. Shell Programming and Scripting

change text color in postscript file

Hi everyone, I have a program that produces postscript files on the fly The color of the files produced are in black and white I want to change the text color of postscript file as the file is being produced without having to manually go into the ps file and change it myself. Any Ideas?... (5 Replies)
Discussion started by: walforum
5 Replies

4. Shell Programming and Scripting

XML to Text file Parsing Using shell scripting

Hi folks, Need some help with XML to text file parsing , the following is the content of the XML File. <xn:SubNetwork id="SNJNPRZDCR0R03"> <xn:MeContext id="PRSJU0005"> <xn:VsDataContainer id="PRSJU0005"> <xn:attributes> ... (6 Replies)
Discussion started by: tech_frk
6 Replies

5. Solaris

XML to Text file Parsing Using shell scripting

Hi, I want to parse an XML File using Shell Script preferably by using awk command, I/P file is : <gn:ExternalGsmCell id="016P3A"> <gn:attributes> <gn:mnc>410</gn:mnc> <gn:mcc>310</gn:mcc> <gn:lac>8016</gn:lac> ... (2 Replies)
Discussion started by: tech_frk
2 Replies

6. Shell Programming and Scripting

Scripting Help needed with a text file.

Hi, Iam a novice to unix shell scripting, need a help from you guys.The scenario is as follows, i have the following Text file. order No Company Category 21 aaa A 24 aaa A 87 aaa B 98 aaa B 23 abc A 45 abc B 25 bbb A 76 wes A 66 ... (6 Replies)
Discussion started by: tech_frk
6 Replies

7. Shell Programming and Scripting

Change the text in 2nd column in file

Legends, I have following entries in a file. I want to toggle the entry of 2nd column. TRUE/FALSE i tried using perl -p -i -e but the problem is, if instead of "tab" space after 1st column, there is a character or multi character space then this won't work. perl -p -i -e... (6 Replies)
Discussion started by: sdosanjh
6 Replies

8. Shell Programming and Scripting

Shell scripting:from text file to CSV

Hello friends, I have a file as follows: "empty line" content1 content2 content3 content1 content2 content3 content1 content2 content3 It starts with an empty line, how can i get a csv like this: (12 Replies)
Discussion started by: kraterions
12 Replies

9. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

10. UNIX for Beginners Questions & Answers

How to change name of the file with first line of the file which has some unwanted text in it?

I have a log file, which i have divided into 14 files using csplit, the file looks like below test-000000 test-000001 #and so on until 14 now I want all the 14 files generated to be renamed as the some part of test in first line of the file how can i eliminate the unwanted text? sample... (5 Replies)
Discussion started by: Sekhar419
5 Replies
MKTEMP(1)						    BSD General Commands Manual 						 MKTEMP(1)

NAME
mktemp -- make temporary file name (unique) SYNOPSIS
mktemp [-d] [-q] [-t prefix] [-u] template ... mktemp [-d] [-q] [-u] -t prefix DESCRIPTION
The mktemp utility takes each of the given file name templates and overwrites a portion of it to create a file name. This file name is unique and suitable for use by the application. The template may be any file name with some number of 'Xs' appended to it, for example /tmp/temp.XXXX. The trailing 'Xs' are replaced with the current process number and/or a unique letter combination. The number of unique file names mktemp can return depends on the number of 'Xs' provided; six 'Xs' will result in mktemp selecting 1 of 56800235584 (62 ** 6) pos- sible file names. If mktemp can successfully generate a unique file name, the file is created with mode 0600 (unless the -u flag is given) and the filename is printed to standard output. If the -t prefix option is given, mktemp will generate a template string based on the prefix and the TMPDIR environment variable if set. The default location if TMPDIR is not set is /tmp. Care should be taken to ensure that it is appropriate to use an environment variable poten- tially supplied by the user. If no arguments are passed or if only the -d flag is passed mktemp behaves as if -t tmp was supplied. Any number of temporary files may be created in a single invocation, including one based on the internal template resulting from the -t flag. The mktemp utility is provided to allow shell scripts to safely use temporary files. Traditionally, many shell scripts take the name of the program with the pid as a suffix and use that as a temporary file name. This kind of naming scheme is predictable and the race condition it creates is easy for an attacker to win. A safer, though still inferior, approach is to make a temporary directory using the same naming scheme. While this does allow one to guarantee that a temporary file will not be subverted, it still allows a simple denial of service attack. For these reasons it is suggested that mktemp be used instead. OPTIONS
The available options are as follows: -d Make a directory instead of a file. -q Fail silently if an error occurs. This is useful if a script does not want error output to go to standard error. -t prefix Generate a template (using the supplied prefix and TMPDIR if set) to create a filename template. -u Operate in ``unsafe'' mode. The temp file will be unlinked before mktemp exits. This is slightly better than mktemp(3) but still introduces a race condition. Use of this option is not encouraged. EXIT STATUS
The mktemp utility exits 0 on success, and >0 if an error occurs. EXAMPLES
The following sh(1) fragment illustrates a simple use of mktemp where the script should quit if it cannot get a safe temporary file. tempfoo=`basename $0` TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1 echo "program output" >> $TMPFILE To allow the use of $TMPDIR: tempfoo=`basename $0` TMPFILE=`mktemp -t ${tempfoo}` || exit 1 echo "program output" >> $TMPFILE In this case, we want the script to catch the error itself. tempfoo=`basename $0` TMPFILE=`mktemp -q /tmp/${tempfoo}.XXXXXX` if [ $? -ne 0 ]; then echo "$0: Can't create temp file, exiting..." exit 1 fi SEE ALSO
mkdtemp(3), mkstemp(3), mktemp(3), environ(7) HISTORY
A mktemp utility appeared in OpenBSD 2.1. This implementation was written independently based on the OpenBSD man page, and first appeared in FreeBSD 2.2.7. This man page is taken from OpenBSD. BSD
December 30, 2005 BSD
All times are GMT -4. The time now is 03:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy