little tricks to speed things up...
Hi there
I quite new to using UNIX, however I have a certain amount of experience using a UNIX-based astronomy package called IRAF (Image Reduction and Analysis Facility). In IRAF, there are certain commands that are useful when copying and otherwise manipulating files....for example, if I have a list of file names stored in list.txt such as: file1.fit file2.fit file3.fit etc.. #note that .fit files are the image file format used in IRAF I can then copy (and rename) the images by the following: Code:
imcopy @list.txt @list.txt//copied so to clarify what the input and output would be for the above line of code: input output file1.fit file1copied.fit file2.fit file2copied.fit file3.fit file2copied.fit etc.. etc... and this brings me to my second part of the question: it is hopefully clear from the input and output as I just stated it, that the "//" command appends an additional substring to the names contained within the file. This is very useful and a variation of this is that you can also prepend ie. if it were copied//@list.txt instead of @list.txt//copied the result would be: input output file1.fit copiedfile1.fit file2.fit copiedfile2.fit file3.fit copiedfile2.fit etc.. etc... The .fit file format is specific to astronomy and what I am seeking to find out is if UNIX has operators equivelant to "@" and "//" as I think it will allow me to transfer text files (or any other kind of file much more quickly that I currently know how to in UNIX), ie. if that above operators worked with the unix cp command (which it doesn't), to transfer from files from one directory to the other I could use the following command: Code:
cp @list.txt "pathofnewdirectory/"//@list.txt file.txt file2.txt file3.txt the cp command would copy these into the path of my chosen directory...ie: pathofnewdirectory/file.txt pathofnewdirectory/file2.txt pathofnewdirectory/file3.txt to summarise: are there UNIX operators equivelant to "@" and "//" as I specified above? thakns |
Here's a quick n dirty soln
Code:
for file in `cat f.list` Code:
cp $file tdir/${1}${file} http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
Use $(command) instead of backticks.
It can't be confused with sungle quotes, nests easily, and doesn't treat backslashes differently inside. |
:) old habits die hard
|
Quote:
- $(command) is bash specific and can't be used with /bin/sh, that is not bash (on Solaris for sure, may be Debian's dash too) - `command` can not be nested. When it's come to scripting I am paranoid and testing exit status of each command, so instead of Code:
for file in `cat f.list` Code:
res=`cat f.list` || exit The only drawback is that "`" can be confused with "'". Well... Each choice has a price |
Quote:
|
Quote:
2. I never use nested $(command), because after each command I'd like to test exit status 3. doesn't treat backslashes differently inside - can you explain it, please |
Quote:
http://www.linuxquestions.org/questi...kticks-131463/ |
Writing little bash scripts like this can take an entire day (or two), such that one is tempted to just write C code (which one then finds takes 3 or 4 days, by time you add all the extra features that you initially did not plan on).
Off the top of my head, untested, but close to what I usually do. Probably will have fix that $2".fit" somehow. mkdir tmptmptmp cp $1 tmptmptmp rename ".fit" $2".fit" tmptmptmp/* mv tmptmptmp/* $3 rmdir tmptmptmp I have some faint memory of some utility having a copy and rename, but cannot remember where. Maybe midnight commander (mc), or something similar. |
Back to the original question:
If you just want to copy the files to a new directory without renaming (as you mention at the end of your post), there is nothing special to do: Code:
$ cp *.fit path_to_dir Code:
$ mcp "*.fit" "path_to_dir/#1.copied.fit" |
that looks very straight forward, thanks Reuti!
|
Quote:
|
All times are GMT -5. The time now is 07:27 AM. |