Moving alphanumeric files according to the digit in file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving alphanumeric files according to the digit in file name
# 8  
Old 11-24-2017
Fortunately, it's working (for me).

EDIT: OK, let's be constructive. WHAT "is not working", and how? Please post data to work upon (execution logs, error messages). For me, this was the output:
Code:
mkdir -p NewDir123
mv c_g_se123_gb.ph_pl_s.t NewDir123
mkdir -p NewDir1
mv c_g_se1_gb.ph NewDir1
mkdir -p NewDir1
mv c_g_se1_gb.ph_pl_s.t NewDir1
mkdir -p NewDir721
mv c_g_se721_gb.ph NewDir721

And, echoes removed, did exactly what was requested.

Last edited by RudiC; 11-24-2017 at 08:52 AM..
This User Gave Thanks to RudiC For This Post:
# 9  
Old 11-24-2017
Quote:
Originally Posted by RudiC
WHAT "is not working", and how?
Thanks, I am not sure what was the problem as in my pc there was no any directory creating with the code. So here is what I did

Code:
for FN in *.ph*; do TMP=${FN%_${FN#*_*_*_}}; NDTMP="NewDir${TMP#${TMP%%[0-9]*}}"; echo mkdir -p "$NDTMP"; echo mv "$FN" "$NDTMP"; done > find_n_move.sh

chmod +x find_n_move.sh 

Added #!/bin/bash to file 

./find_n_move.sh

So its done. Many Thanks. May be you can also let me what was the problem with

Code:
find -name '*.ph' -exec sh -c 'mkdir -p New_dir"$c" && cp "$@" New_dir"$c"' _ {} +

# 10  
Old 11-24-2017
Of course no directory was created nor was a file moved - the commands were echoed to the screen for control purposes. Redirecting to find_n_move.sh and the running that is one option. One other would be to read my post#6 to its entirety and remove the echoes as proposed.

To your second question: What do you expect people to do with the little info you give? May I repeat myself (post#8): WHAT "is not working", and how? Please post data to work upon (execution logs, error messages.
Aside: your construct cp "$@" New_dir"$c"' _ {} seems a bit weird...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What's the best way to check file permissions before moving files if needed?

Hello, I would like to know if it's a good practice to check the file permissions of the contents of a directory before moving them. For example: mv -- "$directory"/* "$directory"/.* "$directory"/..?* "$destination"The variables $directory and $destination contain the path to an existing... (6 Replies)
Discussion started by: Cacializ
6 Replies

2. Shell Programming and Scripting

Moving files based on file name

Hi All, I have multiple files in the folder, I want to move those files into the other folder on based of name File names: Template_server1_01==> Template_server1_02==>To one directory /Server1 Template_server1_03==> Template_server2_01==> Template_server2_02==>To one... (9 Replies)
Discussion started by: sharsour
9 Replies

3. Shell Programming and Scripting

Moving files based on file creation

Hi, I have a directory having so many number of files. Now I want to move the files which are older than one month (lets say) from this directory to another directory (say BKP dir). Simply, if file is olderthan one month move it from source1 dir to BKP1 dir. My file names doesn't have... (7 Replies)
Discussion started by: karumudi7
7 Replies

4. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

5. Shell Programming and Scripting

Searching Alphanumeric Character From a File

Hi, In a error log file, the error code of a particular error contains both Alphabet and Numbers. My problem statement is to find the error codes from a particular log. That means, I need to search a word, which contains both alphabet and number. Please help me. Below is two examples of error... (1 Reply)
Discussion started by: snehasish_jana
1 Replies

6. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

7. Shell Programming and Scripting

Moving files only by oldest file one at a time

Hi I am want to create a script where the file gets moved from the current folder to a folder transfer based on the oldest first. This script should run one file at a time using a loop. I want it as a loop because I want to do some processing while I have one file. Can anyone guide me on this? (2 Replies)
Discussion started by: chamajid
2 Replies

8. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

9. Shell Programming and Scripting

ksh to compare alphanumeric values from 2 files

Hi there, I want to compare 2nd column which are alphanumeric values from each of the 2 files i.e.,lspv_pre.out and lspv_post.out , if found echo some message. lspv_pre.out hdisk0 00c39eaa451144dd rootvg active hdisk1 00c39eaa45223322 ... (3 Replies)
Discussion started by: mbak
3 Replies

10. Shell Programming and Scripting

Moving files listed in a data file to a new directory using Perl

Hi, I have a data file that lists a number of files. I want to move the files named in that one to another directory. Here's what I have: #!/usr/bin/perl -w open(FILE, "<collision.txt"); my @lines=<FILE>; foreach my $lines (@lines) { system("mv $lines collisions/."); } close(FILE); ... (2 Replies)
Discussion started by: renthead720
2 Replies
Login or Register to Ask a Question