Mv all files with different extensions to a new name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mv all files with different extensions to a new name
# 8  
Old 10-25-2016
Thank you greet_sed and dry!


Great postings. I finally understood your answers! It's working Smilie

I installed the command rename via homebrew. This is a great help too.

Yes, I should move to bash. But I am so accustomed to commands like:

Code:
cp file_w30.tex !#:1:s/_w30/_w31/

would this be possible in bash too?

Thank you again


marek
# 9  
Old 10-25-2016
Hi,

Following one works in bash from terminal through bash history ( Not from the script ) :
Code:
cp file_w30.tex !#:1:s/_w30/_w31/

!# - Refers to current command line typed so far.
1 - Refers to word 1 ( it starts from 0 - cp , 1 - file_w30.tex )
s/// - substitute _w30 to _w31

you can try like this from bash script :
Code:
cp file_w{30,32}.tex


Last edited by greet_sed; 10-25-2016 at 05:42 PM.. Reason: update more text
This User Gave Thanks to greet_sed For This Post:
# 10  
Old 10-25-2016
Hi, marek.
Quote:
Originally Posted by marek
...Yes, I should move to bash. But I am so accustomed to commands like:

Code:
cp file_w30.tex !#:1:s/_w30/_w31/

would this be possible in bash too? ...
Code:
 
READLINE
       This is the library that handles reading input when using  an  interac-
       tive shell, unless the --noediting option is given at shell invocation.
       Line editing is also used when using the -e option to the read builtin.
       By default, the line editing commands are similar to those of Emacs.  A
       vi-style line editing interface is also available.  Line editing can be
       enabled  at  any  time  using  the -o emacs or -o vi options to the set
       builtin (see SHELL BUILTIN COMMANDS below).  To turn off  line  editing
       after  the  shell  is running, use the +o emacs or +o vi options to the
       set builtin.
...
      yank-nth-arg (M-C-y)
              Insert  the  first argument to the previous command (usually the
              second word on the previous line) at point.  With an argument n,
              insert  the nth word from the previous command (the words in the
              previous command  begin  with  word  0).   A  negative  argument
              inserts the nth word from the end of the previous command.  Once
              the argument n is computed, the argument is extracted as if  the
              "!n" history expansion had been specified.

Excerpt from man bash, q.v., describing one (small) part of the emacs editing mode for previously entered commands in the history. This is a very general scheme for editing commands. The advantage is that it uses emacs-like commands, so once you know one, the other is similar. Personally, I use the vi mode.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
# 11  
Old 10-26-2016
Thank you!

Code:
cp file_w{30,32}.tex

That's really amazing! Very elegant! I will definately switch to Bourne shell. Opening a new thread, could somebody help me to move my .tcshrc profile to .bashrc ? Or would this be to childish for this professional forum?

Thanks again

marek
# 12  
Old 10-26-2016
There's nothing like childish questions. But - you can help avoid even the impression by showing a correct and professional approach: formulate your request carefully, show your own attempts and where and how they fail (including details, e.g. error messages), and how you started curing the failures (e.g. applying topics from man pages).

And, yes, START a NEW thread - don't continue this old and solved one.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files with different extensions and same name

Hi, i have two folders. Folder A has 1000+ files with just images named like : 01012015.png 01022015.png etc. Folder B has much more files, part of them with same name as png files folder others not. Instead of folder A wich are only images, these are audio wav files. I need to... (11 Replies)
Discussion started by: Board27
11 Replies

2. UNIX for Dummies Questions & Answers

How to tar files of different extensions in one command

Linux RHEL 5.4 It is easy to create a tarball when you have files same extension For eg: You want to tar all files with the extension .log . This is easy tar -cvf diagnose.tar *.log I have two files with different extensions .log and .sh : error.log myscript.sh I want to create a... (5 Replies)
Discussion started by: John K
5 Replies

3. Shell Programming and Scripting

looping through files with different extensions

Hi all, I am trying to make a for loop invoking files with different extensions (*.ugrd and *.vgrd) and I cant just make it work. Cant figure out how to load the files so as to use them in subsequent commands like the ones in this pseudo code. the files are arranged such that in one date for... (8 Replies)
Discussion started by: ida1215
8 Replies

4. Shell Programming and Scripting

Searching for files with specific extensions

Hi, Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log. I've tried to use ls *.txt *.log which works if there are both... (4 Replies)
Discussion started by: neilmw
4 Replies

5. Shell Programming and Scripting

Rename files extensions

Hello ! i have a few files like ... setup.001 setup.002 setup.003 setup.004 // to setup.095 and i would like to rename those files to ... setup.r01 setup.r02 setup.r03 setup.r04 // to setup.r95 (7 Replies)
Discussion started by: Putazo
7 Replies

6. UNIX for Dummies Questions & Answers

changing extensions for multiple files at once

I copied some files to another folder, and I want to change them from .doc extensions to .txt extensions. I tried using the cp and mv commands, but it didn't work. Is it possible to change file extensions with these commands, and if so how do I do it? I tried using the * wildcard (say cp *.doc... (1 Reply)
Discussion started by: Straitsfan
1 Replies

7. Shell Programming and Scripting

Sorting Files according to their Extensions...

I am trying to write a Korne Shell Script wherein we have to sort files according to their extensions(for eg. 1.sh, 5.sh, 9.sh together; 4.csh, 120.csh, 6.csh together and 7.ksh, 2.ksh, 59.ksh together) and move them to their respective directories viz. sh, csh and ksh... I think,... (1 Reply)
Discussion started by: marconi
1 Replies

8. Shell Programming and Scripting

Find files with 3 different extensions

Hi all, From one directory I need to fetch only files of type *.xls,*.csv,*.txt. I tried the find . -name '*.txt,*.csv,*.xls' -print. But it throws me error. Please do help me on this. Thanks Mahalakshmi.A (11 Replies)
Discussion started by: mahalakshmi
11 Replies

9. UNIX for Dummies Questions & Answers

List Files by Extensions

I have a unix directory with 500 plus files . When I do a ls -lR I can see ALL the files here . How can I sort this by the files extensions ? I can't enter ls -lR *.ext1 *.ext2 *.ext3 etc in case I miss out some files . (2 Replies)
Discussion started by: newbienix
2 Replies

10. UNIX for Dummies Questions & Answers

Command to select files with different extensions

I want to select files which have different extensions such as .cpp, .cs, .h I can select one of them as find . -name "*.cpp" but I want to select all of them in one command only. It should be pretty simple but I'm not able to get it. Any help with the command will be greatly appreciated. (1 Reply)
Discussion started by: MobileUser
1 Replies
Login or Register to Ask a Question