grepping files and then renaming file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grepping files and then renaming file
# 1  
Old 10-29-2012
grepping files and then renaming file

Hi,

What is the easiest way to list a directory with 1000s of filenames, grep it for a certain sequence of numbers, and if found to rename the file by the value you are grepping.

eg

The file I am examining will looks like this:

1234
1224343
2324
244
35665

If I am examining a list of files in a given directory and grepping them for values in the file, if the value in the respective row is found to rename that file by the value of the row?

Thanks in advance
# 2  
Old 10-29-2012
If 1234 is the sequence number:-

Code:
find . -name "*" -type f -exec grep -l 1234 {} \; -exec mv {} 1234 \;

Note: please make sure you don't have the same sequence number in more than one file.

Last edited by Yoda; 10-29-2012 at 07:16 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming files by appending string from within file to filename

Greetings. I am working in a Linux environment and am trying to figure out a way to rename files in a directory by appending a unique strings that appears within a certain area in those files. I have gotten as far as identifying what that particular unique string is with a command like the... (10 Replies)
Discussion started by: HLee1981
10 Replies

2. UNIX for Beginners Questions & Answers

Splitting the XML file and renaming the files

Hello Gurus, I have a requirement to split the xml file into different xml files. Can you please help me with that? Here is my Source XML file <jms-system-resource> <name>PS6SOAJMSModule</name> <target>soa_server1</target> <sub-deployment> ... (3 Replies)
Discussion started by: Siv51427882
3 Replies

3. Shell Programming and Scripting

Copying files to a directory, renaming it if a file with the same name already exists

Hi All, I need to copy files from one directory to another with the files to be renamed while copying if a file with the same name already exists in the target directory. THanks, Dev (2 Replies)
Discussion started by: dev.devil.1983
2 Replies

4. Shell Programming and Scripting

Splitting file into multiple files and renaming them

Hi all, Newbie here. First of all, sorry if I made any mistakes while posting this question in terms of rules. Correct me if I am wrong. :b: I have a .dat file whose name is in the format of 20170311_abc_xyz.dat. The file consists of records whose first column consists of multiple dates in... (2 Replies)
Discussion started by: chanduris
2 Replies

5. Shell Programming and Scripting

Renaming the file name for n number of files

Hi , I am kind of new to shell scripting and found a situation to handle ... I have few files which will be ftpd in to our sustem , the file names needs to be renamed based on condition. ------------ Eg file names :- AE_JUNFOR_2013_MTD_2013-04-09-08-30-09.TXT... (6 Replies)
Discussion started by: chillblue
6 Replies

6. Shell Programming and Scripting

Renaming all files inside a zipped file

Hi, To all the Unix gurus this should be a simple task, but as a newbie I'm finding it hard to crack this. Any help is highly appreciated... Scenario: Step 1 : Move zip file from FTP folder to WORK folder Step 2: Unzip the file "Sample_YYYYMMDDHHMMSS.tar.gz" which contains many file... (10 Replies)
Discussion started by: asandy1234
10 Replies

7. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

8. UNIX for Dummies Questions & Answers

Renaming files in one file from names in other

Hi Guys, I have a small problem of renaming multiple files. For example I have names of a set of files in one directory like K2_34625-34675 K7_988963-988983 K12_773882-7734102 and the other set corresponding to the same is U_P_321_9_3_11.ab1 U_P_322_9_3_11.ab1 U_P_323_9_3_11.ab1 Now... (23 Replies)
Discussion started by: pawannoel
23 Replies

9. Shell Programming and Scripting

Renaming files by matching info from a separate file

Hi All, I could use a bit of help with this as I'm at a loss. I have a number of files all named accordingly: I have a separate text file that is as follows: What I want to do is end up with: I don't know how to do this, though I'm certain it can be done, and would rather learn how... (14 Replies)
Discussion started by: Demosthenes
14 Replies

10. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies
Login or Register to Ask a Question