Rename the file with specific pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename the file with specific pattern
# 1  
Old 02-22-2014
Rename the file with specific pattern

Hello

I am making a script where I need to rename the files but with different names.The file name could be change according to the product
I made a logic but that is not working properly
Code:
 arr=$(echo a@b@c | tr "@" "\n")
 echo $arr
 output is a b c
 arry=$(echo d@e@f | tr "@" "\n")
 echo $arry
 output is d e f
 for a in $arr;do for l in $arry;do echo $a$l;done;done

But It is not giving me the desiered output.It is giving me the below output
Code:
ad
ae
af
bd
be
bf
cd
ce
cf

where as I need the below output
Code:
ad
be
cf

Please suggest
# 2  
Old 02-22-2014
Your code is not using or creating any filenames. The subject line of this thread is "Rename the file with specific pattern".

Is this a homework assignment?

What files do you have?

What specific pattern do you want to match?

What new name do you want to give to the file(s) that match the pattern?

What OS and shell are you using?
# 3  
Old 02-22-2014
Hi.
Quote:
Originally Posted by anuragpgtgerman
... where as I need the below output
Code:
ad
be
cf

...
Code:
$ paste -d "" <(echo -e "a\nb\nc" ) <( echo -e "d\ne\nf" )
ad
be
cf

If this was for others would probably use printf instead of echo
Code:
$ paste -d "" <(printf "a\nb\nc" ) <( printf "d\ne\nf" )
ad
be
cf

This is for system:
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
bash GNU bash 3.2.39
echo - is a shell builtin [bash]
paste (GNU coreutils) 6.10

Best wishes ... cheers, drl
# 4  
Old 02-22-2014
As drl produced expected output, like this also you may try using sed, BTW whats your ultimate aim ? Do you think your description is clear ?

Code:
$ arr="a@b@c"
$ arry="d@e@f"
$ paste -d'\0' <(sed 's/@/\n/g' <<<$arr) <(sed 's/@/\n/g' <<<$arry)
ad
be
cf

# 5  
Old 02-22-2014
My description was not clear.I apologies for this

my intention was to rename the file here a b c are files which will renamed with d e and f files.I was using the above logic in my sciript to rename it.File a should be replaced with d,b file with e and c with f.

---------- Post updated at 02:25 PM ---------- Previous update was at 02:23 PM ----------

I am using Linux and bash shell
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename text file with a specific pattern in directory

I am trying to rename all text files in a directory that match a pattern. The current command below seems to be using the directory path in the name and since it already exists, will not do the rename. I am not sure what I am missing? Thank you :). Files to rename in... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Rename files to match file list pattern

Hi All, I have 100 folders with the first delimiter has a unique name i.e (123_hello and 575_hello) and each folder have atlist 1000 plus files with naming convention i.e (575_hello_1.iso ... 575_hello_1000.iso). 575_hello/575_hello_1.iso 575_hello/575_hello_2.iso 575_hello/575_hello_3.iso... (8 Replies)
Discussion started by: lxdorney
8 Replies

3. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

5. Shell Programming and Scripting

How to find and rename of particular pattern in file.?

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

Multiple File Rename based on pattern - one line

All, I wanted to copy the files From: Daily_XYZ_TEST_1.csv Daily_XYZ_TEST_2.csv Daily_XYZ_TEST_3.csv Daily_XYZ_TEST_4.csv To: Daily_ABC_TEST_1.csv Daily_ABC_TEST_2.csv Daily_ABC_TEST_3.csv Daily_ABC_TEST_4.csv I have tried the rename command but it is not working (5 Replies)
Discussion started by: alfredo123
5 Replies

7. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

8. Shell Programming and Scripting

Rename a file based on a specific separator

Hello, I am new to shell I have a folder which contains a list of files, all the files contain the separator : I need to replace this character for all the filenames (by batch) ex: hello:world should become hello-world please help Thanks (3 Replies)
Discussion started by: sikilaklak
3 Replies

9. Shell Programming and Scripting

extract specific string and rename file

Hi all, I am working on a small prog.. i have a file.txt which contains random data... K LINES V4 ADD CODE `COMPANY` ADD CODE `DISTRIBUTOR` SEQ NAME^K LINES V5 SEQ NAME^K LINES V6 ADD `PACK-LDATE` SEQ NAME^K^KCOMMAND END^KHEADINFO... (1 Reply)
Discussion started by: mukeshguliao
1 Replies

10. Shell Programming and Scripting

Extract specific pattern from a file

Hi All, I am a newbie to Shell Scripting. I have a File The Server Name XXX002 ------------------------- 2.1 LAPD Iface Id Link MTU Side ecc_3_1 4 Up 512 User ecc_3_2 5 Up 512 User The Server Name XXX003 ------------------------- 2.1 LAPD (4 Replies)
Discussion started by: athreyavc
4 Replies
Login or Register to Ask a Question