Global search ok...but replace?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Global search ok...but replace?
# 1  
Old 03-25-2004
Global search ok...but replace?

Gurus,

I have in my /tmp directory 26 files "filea", "fileb"..."filez". Each file contains the name of a database 'dwora' at many, many places within each file.

My boss decided to change the name of the db so I need to do (what i'd call) a global search&replace of that string in all my files.

So far, I am able to accomplish the following:
[orcl@dev1]/orcl/tmp/find . -name 'file*' -exec grep dwmora {} \; -exec sed 's/dwora/dworacle/g' {} \;

it outputs to my terminal/screen successfully. However, I want to output my mods in each file from "file*" to "file*.new"....and I can't seem to find the right syntax. I know I can do sed 's/dwora/dworacle/g' filea > filea.new but when I try for multiple files at once, it fails.

What am I missing here?Help, please!
Smilie

ps: I am running HP-UX dev1 B.11.00 U 9000/800
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Global replace command help

Hello - I am trying to use a global replace command but its not working. Here is the cmd I am using in vi: :%s/OLD/NEW/g However, in my "NEW" I already have a "/" which is not making the replace work: :%s/mytestscript.com:33232/mytestscript:70245/test.com/g the... (2 Replies)
Discussion started by: DallasT
2 Replies

2. Shell Programming and Scripting

Global replace with perl in bash

I am newbie to perl, I am trying to use the below syntax to replace globally a string with a variable. $ bash -version GNU bash, version 2.05b.0(1)-release (powerpc-ibm-aix5.1) Copyright (C) 2002 Free Software Foundation, Inc. $ perl -version This is perl, v5.8.8 built for... (2 Replies)
Discussion started by: jville
2 Replies

3. UNIX for Dummies Questions & Answers

Vi global replace command

I am wondering what way, I can remove a certain text with nothing. for example: MyVariable=Y7UHNI to only: Y7UHNI removing 'MyVariable=' globally? thanks (1 Reply)
Discussion started by: DallasT
1 Replies

4. Shell Programming and Scripting

Global search and replace multi line file

Hello I need to search for a mult-line strngs(with spaces in between and qoted) in a file1 and replace that text with Fixed string globally in file1. The strng to search for is in file2. The file is big with some 20K records. so speed and effciency is required file1: (where srch & rplc... (0 Replies)
Discussion started by: Hiano
0 Replies

5. Shell Programming and Scripting

Global replace in vi with no escape required

Hi all, I want to replace a string of words but i dont want to worry about escaping the characters in that string . For e.g. If my string is "work/" and i want to replace it with "nowork" .I have to type %s/work\//nowork/g Is there a way by which I wont need to worry about the data in... (1 Reply)
Discussion started by: sachinpawar2308
1 Replies

6. Shell Programming and Scripting

Global search and replace across multiple files

Hi all I'm in need of a command which can replace a specified string with another string - across multiple files within multiple sub-directories (I intend to run it from / ) I've used the following to get a list of the files: find . | xargs grep <string1> But that's as far as I've got.... (7 Replies)
Discussion started by: huskie69
7 Replies

7. UNIX for Dummies Questions & Answers

global search and replacement of a non-ascii character

Hi, I need to do a global search and replacement of a non-ascii character. Let me first give the background of my problem. Very frequently, I need to copy set of references from different sources. Typically, a reference would like this: Banumathy et al., 2002 G. Banumathy, V. Singh and U.... (1 Reply)
Discussion started by: effjay
1 Replies

8. Shell Programming and Scripting

Global replace with sed

Hi, I need to change some strings from A to B in a number of files within a directory. Please can someone advise how do I do that? Many thanks (5 Replies)
Discussion started by: canary
5 Replies

9. Shell Programming and Scripting

Perl: Global Search and replace

I have a file where the rows correspond to individuals and the columns are about 106 variables. Each variable is coded as either ACGT, and "missing" is coded as blank. This is a tab delimited file. I'm trying to replace all blanks (" ") with 0. The simple script I have is only replacing some of the... (3 Replies)
Discussion started by: epi8
3 Replies

10. Shell Programming and Scripting

global replace...

Hi, I have a dir containing many shell scripts. Each of these shell scripts state a database name (always the same), which I need to change to be a new database. grep <database name> * brings back all the lines containing the database name. However, I need to change them to be something... (1 Reply)
Discussion started by: topcat8
1 Replies
Login or Register to Ask a Question
find(1) 						      General Commands Manual							   find(1)

NAME
find - Finds files matching an expression SYNOPSIS
find pathname... expression STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: find: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
Starting point in the directory hierarchy. Series of arguments built as described in the DESCRIPTION section. DESCRIPTION
The find command recursively searches the directory tree for each specified path name, seeking files that match the Boolean expression. The output from the find command varies depending on the terms used in expression. Pathname The pathname operand is the starting point in a directory tree for the search. If a file name is used for the path name, the current direc- tory is assumed. A null path name is not permitted, i.e., find "" returns an error. Expressions In the following descriptions, the argument number is a decimal integer that can be specified as +number (more than number), -number (less than number), or number (exactly number). TRUE if the file was accessed in the past number days, where number is interpreted as described in this reference page. Writes the current file to device in cpio format. See the cpio command. TRUE if the file inode was changed in the past number days, where number is interpreted as described in this reference page. Always evaluates to TRUE. This causes the descent of the directory hierarchy to be done so that all entries in a directory are affected before the directory itself. This can be useful when find is used with cpio to transfer files that are contained in directories without write permission. TRUE if the command runs and returns a 0 (zero) value as exit status. The end of command must be punctuated by a quoted or escaped ; (semicolon). The command parameter { } is replaced by the current path name. TRUE if expression is TRUE. Always evaluates to TRUE . Causes symbolic links to be followed. When following symbolic links, the find command keeps track of the directories visited so that infinite loops can be detected. For example, a loop can occur if a symbolic link points to an ancestor. This expression should not be used with the -type type expression where type is of type l. TRUE if the file system to which the file belongs is of the type type as follows: [Tru64 UNIX] UNIX File System (Berkeley fast file system) or a swap partition [Tru64 UNIX] Network File System (NFS), Version 2 protocol [Tru64 UNIX] Memory File System (RAM Disk) (See mfs(8)) [Tru64 UNIX] PC File System [Tru64 UNIX] System V File System [Tru64 UNIX] ISO 9660 or High Sierra Formatted (CD-ROM) File System [Tru64 UNIX] DCE Distributed File System [Tru64 UNIX] DCE Episode File System [Tru64 UNIX] Process File System (used by debug- gers) [Tru64 UNIX] Advanced File System (AdvFS) [Tru64 UNIX] File on File mount (used by streams) [Tru64 UNIX] File Descriptor File Sys- tem (used by streams) [Tru64 UNIX] Reserved for third-party file systems [Tru64 UNIX] Network File System, Version 3 protocol TRUE if the file belongs to group. If group is numeric and does not appear as a group name in the /etc/group file, it is interpreted as a group ID. TRUE if file has inode number. TRUE if file has inode number. [Tru64 UNIX] TRUE if the file has number links. See the ln command. Always evaluates to TRUE; causes pathname to be printed together with its associated statistics. These include, respectively, inode num- ber, size in kilobytes (1024 bytes), protection mode, number of hard links, user, group, size in bytes, and modification time. If the file is a special file, the size field will contain instead the major and minor device numbers. [Tru64 UNIX] The find command does not follow symbolic links to other directories or files. Rather, it applies the specified selection criteria to the symbolic links themselves, treating them as if they were ordinary files. (For more information on sym- bolic links, see ln(1).) [Tru64 UNIX] TRUE if the current file is on the same file system as the current starting path name. TRUE if the file was modified in the past number days, where number is interpreted as described in this reference page. TRUE if file matches the file name. You can use pattern-matching characters, provided they are quoted. In an expression such as [a-z], the dash means through according to the current collating sequence. The collating sequence is determined by the value of the LC_COLLATE envi- ronment variable. See the reference page for your current shell for a more detailed explanation of pattern matching and quoting spe- cial characters. Sets the input/output size (5120 bytes by default) to size. TRUE if the current file was modified more recently than the file indicated by file. The find command asks you whether it should start command. If your response begins with y, or the locale's equivalent of a y, command is started. The end of command must be punctuated by a quoted or escaped semicolon. TRUE if the file permission code of the file exactly matches octal_number (see the chmod(1) reference page). The octal_number argument may be up to three octal digits. If you want to test the higher-order permission bits (the set-user-ID bit or set-group-ID bit, for example), prefix the octal_number argument with a - (dash). This makes more flag bits significant (see the stat system call for an explanation of the additional bits), and also changes the comparison to (flags&octal_number)==octal_number Always TRUE; causes the current path name to be displayed. If an expression is not specified or if expression is not -ok or -exec, -print is the default. For example, the following commands produce the same result: find . find . -print find . -name "*" Always TRUE. Prunes the search tree at the file. That is, if the current path name is a directory, the find command does not descend into that directory. In a networking environment, this flag keeps the find command from searching through remote file sys- tems. TRUE if the file is number blocks long (512 bytes per block). For this comparison, the file size is rounded up to the nearest block. TRUE if the file is number bytes long. TRUE if the file is number kilobytes long. For this comparison, the file size is rounded up to the nearest kilobyte. TRUE if the file type is of the specified type as follows: [Tru64 UNIX] Block special file [Tru64 UNIX] Character special file Directory Plain file [Tru64 UNIX] Symbolic link [Tru64 UNIX] FIFO (a named pipe) [Tru64 UNIX] Socket TRUE if the file belongs to user. If user is numeric and does not appear as a login name in the /etc/passwd file, it is interpreted as a user ID. Always TRUE; causes find not to traverse down a file system different from the one on which the cur- rent path name resides. The primaries may be combined using the following operators (in descending order of precedence): A parenthesized group of primaries and operators. Parentheses are special to the shell and must be escaped. Parentheses must be separated from other primaries and operators by at least one space. The negation of a primary (! is the unary not operator). Concatenation of primaries (the and operation is implied by the juxtaposition of two primaries but can also be specified explicitly with the -a operator). Alternation of primaries (-o is the or operator). To avoid unpredictable results when using a range expression to match a class of characters, use a character class expression rather than a standard range expression. For information about character class expressions, see the grep command. EXIT STATUS
The following exit values are returned: All pathname operands were traversed successfully. An error occurred. RETURN VALUES
The -exec command expression evaluates TRUE if the command runs and returns a 0 (zero) value as exit status. EXAMPLES
To list all files in the file system with a given base file name, enter: find / -name .profile -print This searches the entire file system and writes the complete path names of all files named / (backslash) tells find to search the root directory and all of its subdirectories. This may take a while, so it is best to limit the search by specifying the directo- ries where you think the files might be. To list the files with a specific permission code in the current directory tree, enter: find . -perm 0600 -print This lists the names of the files that have only owner-read and owner-write permission. The (dot) tells find to search the current directory and its subdirectories. See the chmod(1) reference page for details about permission codes. To search several directories for files with certain permission codes, enter: find manual clients proposals -perm -0600 -print This lists the names of the files that have owner-read and owner-write permission and possibly other permissions. The directories manual, clients, and proposals, and their subdirectories, are searched. Note that -perm 0600 in the previous example selects only files with permission codes that match 0600 exactly. In this example, -perm -0600 selects files with permission codes that allow at least the accesses indicated by 0600. This also matches the permission codes 0622 and 2744. To search for regular files with mul- tiple links, enter: find . -type f -links +1 -print This lists the names of the ordinary files (-type f) that have more than one link (-links +1). Note that every directory has at least two links: the entry in its parent directory and its own (dot) entry. See the ln command for details about multiple file links. To find all accessible files whose path name begins with find, enter: find find -print To remove all files named a.out or *.o that have not been accessed for a week and that are not mounted using nfs, enter: find / ( -name a.out -o -name '*.o' ) -atime +7 -exec rm {} ; -o -fstype nfs -prune To find all files modified within the last 24 hours, enter: find . -mtime 1 -print To find all files on the root file system, enter: find / -mount -print To write all the files on the root file system to tape, enter: find / -mount -print -cpio /dev/tape/tape?_d0 cpio -iBvt </dev/rmt?h To find all the mount points on the root file system, enter: find / ! -mount -print The next several examples show how to build complex expressions using the available operators. These examples use the directory structure that follows: % ls -al total 77 drwxr-xr-x 9 me users 8192 Nov 6 17:28 . drwxrwxrwx 47 me users 8192 Nov 6 13:30 .. -rw- r--r-- 1 me users 1559 Dec 23 1996 7 -rw-r--r-- 1 me users 7 May 30 12:22 abc -rw-r--r-- 1 me users 0 Nov 5 17:44 ccc drwxr-xr-x 2 me users 8192 Apr 6 1997 crn drwxr-xr-x 3 me users 8192 Mar 23 1997 crypto drwxr-xr-x 2 me users 8192 Sep 12 14:24 exp -rwx--x--x 1 me users 0 Nov 1 1996 filea ---x-w--wx 1 me users 0 Nov 1 1996 fileb -rw-r--r-- 1 me adm 0 Jun 13 13:43 filek -rwxr- xr-x 1 me users 216 Nov 1 1996 filet -rw-r--r-- 1 me users 0 Nov 6 17:35 find -rw-r--r-- 1 me adm 0 Jun 13 13:43 gfilek -rwxr-xr-x 1 me users 216 Nov 6 17:28 gfilet drwxr-xr-x 2 me users 8192 Oct 23 13:49 h4d -rw-r--r-- 1 me adm 0 Jun 13 13:43 hfilek drwxr-xr-x 2 me users 8192 Oct 23 11:50 resume drwxr-xr-x 2 me users 8192 Sep 8 13:31 timtst -rw-r--r-- 1 me users 0 Nov 6 17:25 typescript drwxr-xr-x 2 me users 8192 Dec 18 1996 wordgame The following example finds all files that have a name starting with file. Notice that the asterisk must be escaped to prevent the shell from interpreting it as a special character. % find . -name file* ./filea ./fileb ./filet ./filek The following example finds all files that have a name starting with file and an owning group of adm. Notice that this is the default behavior, and is identical to the next example using the -a operator. % find . -name file* -group adm ./filek The following example finds all files that have a name starting with file and an owning group of adm. Notice that this is identical to the prior example of the default behavior. % find . -name file* -a -group adm ./filek The following example finds all files that have a name starting with file or that have an owning group of adm. % find . -name file* -o -group adm ./filea ./fileb ./filet ./filek ./gfilek ./hfilek The following example finds all files that have a name starting with file or that have an owning group of adm and a name starting with gf. % find . -name file* -o -group adm -name gf* ./filea ./fileb ./filet ./filek ./gfilek The following example finds all files that have a name starting with file and that have an owning group of adm or a name starting with gf. % find . -name file* -a -group adm -o -name gf* ./filek ./gfilek ./gfilet The following example finds all files that have an owning group other than the group users. % find . ! -group users ./filek ./gfilek ./hfilek The following example finds all files owned by the group users and that have a name starting with file or that have a name starting with cc. % find . ( -group users -a -name file* ) -o -name cc* ./filea ./fileb ./filet ./ccc The following example finds all files not owned by the group users and that have a name starting with file or that have a name starting with cc. % find . ( ! -group users -a -name file* ) -o -name cc* ./filek ./ccc ENVIRONMENT VARIABLES
The following environment variables affect the execution of find: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for- mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. Determines the location of command for -exec and -ok primaries. FILES
Contains group information. Contains user information. SEE ALSO
Commands: chmod(1), cpio(1), df(1), grep(1), ln(1), mount(8), Bourne shell sh(1b), POSIX shell sh(1p), test(1) Functions: mount(2), stat(2) Routines: getvfsbyname(3) Files: fs(4), fstab(4), cdfs(4) Standards: standards(5) find(1)