cp times.csv{,.bak} -> makes a copy with *.bak extension. How this works?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cp times.csv{,.bak} -> makes a copy with *.bak extension. How this works?
# 1  
Old 11-18-2011
cp times.csv{,.bak} -> makes a copy with *.bak extension. How this works?

Hi

Code:
cp times.csv{,.bak}

makes a copy with *.bak extension. How this works?

Whats the gimmick here? Can't google special characters
# 2  
Old 11-18-2011
If it works, it's built into your shell, and no gimmickry required(!).

Here's an extract from the bash man page on it:
Code:
Brace Expansion
       Brace expansion is a mechanism by which arbitrary strings may be generated.  This mechanism is similar to pathname expan-
       sion, but the filenames generated need not exist.  Patterns to be brace expanded take the form of an  optional  preamble,
       followed  by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an
       optional postscript.  The preamble is prefixed to each string contained within the braces, and  the  postscript  is  then
       appended to each resulting string, expanding left to right.

       Brace  expansions  may  be nested.  The results of each expanded string are not sorted; left to right order is preserved.
       For example, a{d,c,b}e expands into `ade ace abe'.

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk executes and works but only on copy of file

The tab-delimited file below using the awk produces a blank output. However, when I copy the same lines in file to a new document and execute the awk I get the desired result. The awk counts the unique characters before the : in $7 according to the id in $1. The awk seems to work but I can not... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

3. Shell Programming and Scripting

Copy files with extension .sh

Hi all... I am trying to copy all my shell script to some directory using following command, I want to simplify it by not using awk..please some one help me.... find -name "*.sh" | awk -F"/" '{a=$NF;gsub(".sh",x,a);cmd="cp"" " $0" ""/home/akshay/MY_ALL/"a"_"++i".sh";system(cmd)}' (3 Replies)
Discussion started by: Akshay Hegde
3 Replies

4. Shell Programming and Scripting

Copy n paste n times

I have one mainframe copy book where I want to copy n times depend on occurs which mention below. Example: Below highlighted row mention “occurs 2 times” so I need to copy 2 times till next label 10. C14992 10 FILLER PIC X(2835). 01 ... (7 Replies)
Discussion started by: srivalli
7 Replies

5. Shell Programming and Scripting

Cp and create files as {,.bak}

Hello Guys, As the perefect lazy administrator was wondering if is possible to create several files from one instance as the quick tip of doing this using "cp" ; $ cp demofile demofile.bak or $ cp demofile{,.bak} $ls demofile.bak Something like the following e.g. using "touch" ... ... (7 Replies)
Discussion started by: VicoAndres
7 Replies

6. UNIX for Dummies Questions & Answers

How to copy set of lines n times?

I have a file with following data A B C I would like to print like this n times(For eg:n times) A B C A B C A B C A B C A (3 Replies)
Discussion started by: nsuresh316
3 Replies

7. UNIX for Dummies Questions & Answers

Copy files with same name but different extension from 2 different directory

Hi all, i have 2 directory of files, the first directory(ext1directory) contain files of extension .ext1 and the second directory(allextdirectory) contains files of multiple extensions (.ext1,.ext2,.ext3,..) so i want to copy the files from directory 2(allextdirectory) that have the same name... (8 Replies)
Discussion started by: shelladdict
8 Replies

8. Shell Programming and Scripting

Copy Column Multiple Times

Hello, I wonder if it my problem can be solved. Inside File1.txt, there are 3 columns. Inside File 2.txt, contain certain variable(in this case, only "3"). So I want to : (copy File 1 x Variable in File 2). Expected result are File 3.txt. Any help are really appreciated. File 1.txt -92.033... (4 Replies)
Discussion started by: guns
4 Replies

9. Shell Programming and Scripting

copy files with new extension in same directory

I've been able to find all the extensionless files named photos using the command: find /usr/local/apache/htdocs -name photos -print0 I need to copy those files to the name photos.php in their same directory. I've found a bunch of xarg examples for moving to other directories but I wasn't... (7 Replies)
Discussion started by: dheian
7 Replies

10. UNIX for Advanced & Expert Users

File extension search and copy

Hi need to know if we can write a shell script to find files for a particular format;s ie both .csv and .txt in a particular folder and then copy them to a new folder on a dialy basis. Does anyone know how this can be accomplished? Thanks, Sandeep (20 Replies)
Discussion started by: bsandeep_80
20 Replies
Login or Register to Ask a Question