Sponsored Content
Top Forums Shell Programming and Scripting Replacing string in all instances (both filenames and file contents) in a directory Post 302284295 by Franklin52 on Thursday 5th of February 2009 07:47:50 AM
Old 02-05-2009
To use the variables with awk:

Code:
new=1500
old=2000

awk -v n=$new o=$old '{awk '{f=$0;gsub(o,n);......}'

Regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing all instances of an IP address in a log file.

I know this should be simple but the periods in the string replacement are throwing me off. What I want to do is replace 1.1.1.1 in my access.log file with 2.2.2.2 I have tried using 'tr' but its being thrown off by the periods and replacing all sorts of stuff in the file. What do I need... (2 Replies)
Discussion started by: LordJezo
2 Replies

2. Shell Programming and Scripting

Replacing contents in a file from multiple programmes

Hi All, I have a query on Perl. I have a text file which has 3 lines, i want to only replace the first line with my replaced text and keep the rest of the text. FOr eg Before change --> echo:a:pending echo:b:pending echo:c:pending After change ---> echo:a:done echo:b:pending... (1 Reply)
Discussion started by: tosatesh
1 Replies

3. Shell Programming and Scripting

replacing text with contents from another file

I'm trying to change the ramfs size in kernel .config automatically. I have a ramfs_size file generated with du -s cat ramfs_size 64512 I want to replace the linux .config's ramdisk size with the above value CONFIG_BLK_DEV_RAM_SIZE=73728 Right now I'm doing something dumb like: ... (3 Replies)
Discussion started by: amoeba
3 Replies

4. Shell Programming and Scripting

How to select only the most frequent instances of a variable string in a file?

I've got a web access file that I want to grep (or awk or perl or whatever will work!) out the most frequent instances of unique IP entries. Meaning the file looks something like this: I'd like to run a sort or grep (or whatever) that will only select out the lines from IP's that had the... (7 Replies)
Discussion started by: kevinmccallum
7 Replies

5. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

6. Shell Programming and Scripting

replacing all instances in a file

Hi I have some script like this: perl -i -p0e 's/"keyword1-.*?"/"keyword2"/s' file to replace some keyword, but it replaces only the first instance of the keyword how can i get it to replace all instances? thanks! (2 Replies)
Discussion started by: vanessafan99
2 Replies

7. UNIX for Dummies Questions & Answers

Replacing a particular string in all files in folder and file contents

I need to replace all filesnames in a folder as well as its content from AK6 to AK11. Eg Folder has files AK6-Create.xml, AK6-system.py etc.. the files names as well as contents should be changes to AK9-Create.xml, AK9-system.py etc All files are xml and python scripts. ---------- Post... (0 Replies)
Discussion started by: Candid247
0 Replies

8. Shell Programming and Scripting

How to get filenames in a directory and write them in to a file?

I need to get the names of files which are starting with a string testfile. Also i want to create a XML file in the same location and write these file names into the XML. Ex: <path> <dir> <file>testfile1</file> </dir> <dir> <file>testfile2</file> </dir>... (4 Replies)
Discussion started by: vel4ever
4 Replies

9. Shell Programming and Scripting

print all filenames in directory with path to another file

hi, i have a directory at /path/unix with the following files 1.txt 2.txt 3.txt 4.txt I want to make another file called filenames.txt at a different location called /path/home. So, my output file would be /path/home/filenames.txt with contents /path/unix/1.txt... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

10. Shell Programming and Scripting

How to take the filenames from a directory and store into a file??

hi, how can i take the file names from a directory and store only the filenames in the file. suppose i have a directory which contains the following files and subdirectories. $ ls -ltr total 16 -rw-rw-r-- 1 adm etc 4 Aug 6 20:37 s1.txt -rw-rw-r-- 1 adm etc 4 Aug 6 20:37 s2.txt... (11 Replies)
Discussion started by: Little
11 Replies
tmpnam(3)						     Library Functions Manual							 tmpnam(3)

NAME
tmpnam, tempnam - Construct the name for a temporary file LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <stdio.h> char *tmpnam( char *s); char *tempnam( const char *directory, const char *prefix); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: tmpnam(), tempnam(): XSH4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the address of an array of at least the number of bytes specified by L_tmpnam, a constant defined in the stdio.h header file. Points to the pathname of the directory in which the file is to be created. Points to an initial letter sequence with which the filename begins. The prefix parameter can be null, or it can point to a string of up to 5 bytes to be used as the beginning of the temporary file- name. DESCRIPTION
The tmpnam() and tempnam() functions generate filenames for temporary files. The tmpnam() function generates a filename using the pathname defined as P_tmpdir in the stdio.h header file. Files created using this function reside in a directory intended for temporary use, and their names are unique. It is the application's responsibility to use the unlink() function to remove the files when they are no longer needed. Between the time a filename is created and the file is opened, it is possible for some other process to create a file with the same name. This should not happen if that other process uses these functions or the mktemp() function, and if the filenames are chosen to make dupli- cation by other means unlikely. The tempnam() function allows you to control the choice of a directory. If the directory parameter is null or points to a string that is not a pathname for an appropriate directory, the pathname defined as P_tmpdir in the stdio.h header file is used. If that pathname is not accessible, /tmp is used. You can bypass the selection of a pathname by providing an environment variable, TMPDIR, in the user's environ- ment. The value of the TMPDIR variable is a pathname for the desired temporary file directory. The prefix parameter can be used to specify a prefix of up to 5 bytes for the temporary filename. NOTES
If the s parameter is null, the tmpnam() function places its result into an internal thread-specific buffer and returns a pointer to that area. Subsequent calls to this function from the same thread overwrite this buffer. The tmpnam() function generates a different filename each time it is called. [Tru64 UNIX] If tmpnam() is called more than TMP_MAX times by a single process, it starts recycling previously used names. RETURN VALUES
If the s parameter is null, tmpnam() function places its result into an internal thread-specific buffer and returns a pointer to that area. If the s parameter is not null, it is assumed to be the address of an array of at least the number of bytes specified by the L_tmpnam con- stant. The tmpnam() function places its results into that array and returns the value of the s parameter. Upon successful completion, the tempnam() function returns a pointer to the generated pathname, suitable for use in a subsequent call to the free() function. Otherwise, null is returned and errno is set to indicate the error. ERRORS
If the tempnam() function fails, errno may be set to the following value: Insufficient storage space is available. RELATED INFORMATION
Functions: fopen(3), free(3), malloc(3), mktemp(3), open(2), tmpfile(3), unlink(2) Standards: standards(5) delim off tmpnam(3)
All times are GMT -4. The time now is 06:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy