03-24-2011
Find and Replace then rename file
Hi,
This is probably quite simple for an expert, but I keep getting confused about the best approach, grep, awk, sed.
What I have is a range of files numbered 1 to 100. They go
file1.txt
file2.txt
and so on
In each file I need to find and replace a couple of items and rename add a suffix.
Eg file1-new.txt
file2-new.txt
I'd like to be able to run the shell script for example say it's called Renamer.sh in the command line like this Renamer 1
This would grab the file1.txt create file1-new.txt
Renamer 2 would grab the file2.txt create file2-new.txt and so on.
The find and replace I need is to search one large chunk of text that is in xml format so will include characters such as < " and /
Can someone please point me in the right direction?
Thanks,
Travis
Also
---------- Post updated at 12:20 PM ---------- Previous update was at 11:41 AM ----------
PS. I am working in Mac OSX so may not have the full unix commands.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I build several files by using the cut command to grab select fields(columns) from a really bid csv file. Each file is one column of data. I then put them together using paste command. Here is the code built in tcsh:
cut -d , -f 1 some.csv > 1.csv
cut -d , -f 10 some.csv > 10.csv
paste 1.csv... (2 Replies)
Discussion started by: yankee428
2 Replies
2. Shell Programming and Scripting
Hi Guys,
I need a help. I have 1130 zip files. Each one of them has files including 1 html file with long file name (includes special charactors, Alphabetic and numbers).
I have copied all 1130 zip files to my linux system and extracted using below command.
Find . -name "*.zip" -exec... (7 Replies)
Discussion started by: Rajmani
7 Replies
3. Shell Programming and Scripting
I need help finding a file through terminal and then renaming it automatically.
Here is what I have so far to find the file:
cd /User/Applications
find . */SourceM.app/banner.png | while read line; do mv "$line" banner-.png; done
I want the script to rename the file "banner.png" to... (6 Replies)
Discussion started by: rbisconti97
6 Replies
4. Shell Programming and Scripting
I want to find a file say IIFT and check its size is zero or not. If its zero then I have to rename anothe file say WWFT , which is in another folder to WWFT$Todaysdate.
I tried below command:
cd dir2 (*File WWFT is in dir2)
find dir/ -type f -name 'IIFT*' -size 0 -exec mv WWFT... (3 Replies)
Discussion started by: ammbhhar
3 Replies
5. Shell Programming and Scripting
Hi Guys,
I have folder called /input/temp. Inside the folder I have lot of files. I need to find the file of pattern Article_????_test_?????????.txt and replace by format below.
Article_????_?????????.txt
Below is the one which I tried but it doesn't works can you please help us.... (4 Replies)
Discussion started by: Vinoth Kumar G
4 Replies
6. Shell Programming and Scripting
hi,
Need your help.
I need to write a script for below..
i have two files in directory /home/abc as below:
Watch_20140203_abc.dat
Watchnow_20140203_abc.dat
I have to copy this file from
/home/abc to /home01/home02
after that i have to rename the date part in above two files... (1 Reply)
Discussion started by: Vivekit82
1 Replies
7. UNIX for Dummies Questions & Answers
Have a file in this format This is line one ; line_one
This is line two ; line_two
This is line three ; line_three
This is line four ; line four. I'm trying to make each line a new file called line_one
line_two
line_three
line_four. Tried using split -1 but then I'm back needing to rename... (3 Replies)
Discussion started by: jimmyf
3 Replies
8. Shell Programming and Scripting
Hello Forum.
I have a file called abc.sed with the following commands;
s/1/one/g
s/2/two/g
...
I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat
sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies
9. UNIX for Dummies Questions & Answers
Hi,
I have a directory which contains multiple files with .txt extension, i want to rename all these file to .bak extension using find command, this is what i've tried, please help me to correct this :
find /home/application/test -name '*.txt' -exec rename 's/txt/bak/' {} \;
seems to... (8 Replies)
Discussion started by: mukulverma2408
8 Replies
10. UNIX for Beginners Questions & Answers
Hi All,
I am having below sample data in a file.
I need to find all the line form this file with word ABC and i need to replace the characters at position 120 which is "CO:BOGFDUI"(30chars) in the lines with blank space.
I have tried using grep to find the word with ABC (grep ABC filename),... (3 Replies)
Discussion started by: abhi_123
3 Replies
mv(1) General Commands Manual mv(1)
Name
mv - move or rename files
Syntax
mv [-i] [-f] [-] file1 file2
mv [-i] [-f] [-] file... directory
Description
The command moves (changes the name of) file1 to file2.
If file2 already exists, it is removed before file1 is moved. If file2 has a mode which forbids writing, prints the mode and reads the
standard input to obtain a line. If the line begins with y, the move takes place. If it does not, exits. For further information, see
In the second form, one or more files (plain files or directories) are moved to the directory with their original file-names.
The command refuses to move a file onto itself.
Options
- Interprets all following arguments as file names to allow file names starting with a minus.
-f Force. This option overrides any mode restrictions or the -i switch.
-i Interactive mode. If a move is to supersede an existing file, the system prompts youw with the name of the file fol-
lowed by a question mark. If you type a string that begins with y, the move occurs. If you type any other response,
the move does not occur.
Restrictions
If file1 and file2 lie on different file systems, must copy the file and delete the original. In this case the owner name becomes that of
the copying process and any linking relationship with other files is lost.
See Also
cp(1), ln(1)
mv(1)