Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Using variables to copy files with increasing numerical names. Post 303044901 by RudiC on Sunday 8th of March 2020 11:22:19 AM
Old 03-08-2020
This is a "brace expansion". It is expanded before any other expansions, and it cannot take any variables; read man bash very carefully:

Quote:
Brace Expansion
Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion, 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.
.
.
.
A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer.

.

.
.
Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is
strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.
Those strings, integers, or characters are constants, not variables.
These 2 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

copy files with invalid names

Hi all, I have to copy a directory to another location. While doing so with the cp command I got some errors due to invalid filenames of some files. For example, some files have a colon in their names, which is throwing error. These files are not copied to the destination. How to copy... (1 Reply)
Discussion started by: fermisoft
1 Replies

2. Programming

Adding files of numerical data

Hi I was hoping that maybe someone could help me with a small piece of C code. I have a number of files, which are all of similar layout ie. three lines of text and 5-6 columns of numerical data. I need to add each of the elements of the second column in one file to their counterparts in the second... (17 Replies)
Discussion started by: Boucho
17 Replies

3. Shell Programming and Scripting

compare files by numerical value

Hi everyone, I would love to have a script that does the following: I have one file that looks like that: ATOM 1 BB SER 1 1 -31.958 -25.125 -11.061 1.00 0.00 ATOM 3 BB GLY 1 2 -32.079 -26.085 -14.466 1.00 0.00 ATOM 4 BB VAL 1 3 ... (1 Reply)
Discussion started by: s-layer
1 Replies

4. Shell Programming and Scripting

how can i copy a list of files with different names into others directory have the same name

dear all. how can i copy a list of files with different names into others directory have the same name like i have 3 files 10_10 10_10_11 10_10_11_12 and i have 3 directories 10_10 10_10_11 10_10_11_12 how can i make a loop to cp this files into the directory have the same name like... (0 Replies)
Discussion started by: t17
0 Replies

5. UNIX for Dummies Questions & Answers

How can i copy a list of files with different names into others directory have the same name?

dear all. how can i copy a list of files with different names into others directory have the same name like i have 3 files 10_10 10_10_11 10_10_11_12 and i have 3 directories 10_10 10_10_11 10_10_11_12 how can i make a loop to cp this files into the directory have the same name like... (31 Replies)
Discussion started by: t17
31 Replies

6. Shell Programming and Scripting

how to copy files followed by list of names of all the files in /etc?

....... (2 Replies)
Discussion started by: pcbuilder
2 Replies

7. Shell Programming and Scripting

Finding File Names Ending In 3 Random Numerical Characters

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190 each of this files is in a directory named for the file but excluding the extension. Now the last three numeric characters, in this case 999, can be anything from 001 to 999, I need to... (3 Replies)
Discussion started by: roche.j.mike
3 Replies

8. UNIX for Dummies Questions & Answers

List files according to the numerical value

Hi, I have a large number of files which are named as follows. VF_50, VF_100, VF_150, VF_250, VF_300, VF_350, VF_400, VF_450, VF_500. When I do an 'ls' it arranges the files in the following way VF_100, VF_150, VF_250, VF_300, VF_350, VF_400, VF_450, VF_50, VF_500. Is there a way to... (2 Replies)
Discussion started by: lost.identity
2 Replies

9. Shell Programming and Scripting

Deleting particular files with a numerical suffix

Hello I have a directory with a list of files which have a particular numerical suffix. E.g filename_0 filename_1 filename_18500 filename_10000 I want to delete all files from this directory which have a filename which have a numerical suffix greater than 10540. So any files... (5 Replies)
Discussion started by: kamal_p_99
5 Replies

10. Shell Programming and Scripting

How to create files with two or more variables in its names?

Hi all, Iam writing a perl script to create many files with variables in their name. i am able to do it, if iam using only one variable. But with two variables the file names are NOT getting generated in the way i want. plz help me out. 1. open(SHW,">divw_unsigned_50_50_$k.reset") or die... (4 Replies)
Discussion started by: twistedpair
4 Replies
fnmatch(5)						Standards, Environments, and Macros						fnmatch(5)

NAME
fnmatch - file name pattern matching DESCRIPTION
The pattern matching notation described below is used to specify patterns for matching strings in the shell. Historically, pattern match- ing notation is related to, but slightly different from, the regular expression notation. For this reason, the description of the rules for this pattern matching notation is based on the description of regular expression notation described on the regex(5) manual page. Patterns Matching a Single Character The following patterns matching a single character match a single character: ordinary characters, special pattern characters and pattern bracket expressions. The pattern bracket expression will also match a single collating element. An ordinary character is a pattern that matches itself. It can be any character in the supported character set except for NUL, those spe- cial shell characters that require quoting, and the following three special pattern characters. Matching is based on the bit pattern used for encoding the character, not on the graphic representation of the character. If any character (ordinary, shell special, or pattern spe- cial) is quoted, that pattern will match the character itself. The shell special characters always require quoting. When unquoted and outside a bracket expression, the following three characters will have special meaning in the specification of patterns: ? A question-mark is a pattern that will match any character. * An asterisk is a pattern that will match multiple characters, as described in Patterns Matching Multiple Characters, below. [ The open bracket will introduce a pattern bracket expression. The description of basic regular expression bracket expressions on the regex(5) manual page also applies to the pattern bracket expression, except that the exclamation-mark character ( ! ) replaces the circumflex character (^) in its role in a non-matching list in the regular expression notation. A bracket expression starting with an unquoted circumflex character produces unspecified results. The restriction on a circumflex in a bracket expression is to allow implementations that support pattern matching using the circumflex as the negation character in addition to the exclamation-mark. A portable application must use something like [^!] to match either character. When pattern matching is used where shell quote removal is not performed (such as in the argument to the find -name primary when find is being called using one of the exec functions, or in the pattern argument to the fnmatch(3C) function, special characters can be escaped to remove their special meaning by preceding them with a backslash character. This escaping backslash will be discarded. The sequence \ rep- resents one literal backslash. All of the requirements and effects of quoting on ordinary, shell special and special pattern characters will apply to escaping in this context. Both quoting and escaping are described here because pattern matching must work in three separate circumstances: o Calling directly upon the shell, such as in pathname expansion or in a case statement. All of the following will match the string or file abc: abc "abc" a"b"c ac a[b]c a["b"]c a[]c a[""]c a?c a*c The following will not: "a?c" a*c a[b]c o Calling a utility or function without going through a shell, as described for find(1) and the function fnmatch(3C) o Calling utilities such as find, cpio, tar or pax through the shell command line. In this case, shell quote removal is performed before the utility sees the argument. For example, in: find /bin -name ec[h]o -print after quote removal, the backslashes are presented to find and it treats them as escape characters. Both precede ordinary char- acters, so the c and h represent themselves and echo would be found on many historical systems (that have it in /bin). To find a file name that contained shell special characters or pattern characters, both quoting and escaping are required, such as: pax -r ... "*a(?" to extract a filename ending with a(?. Conforming applications are required to quote or escape the shell special characters (sometimes called metacharacters). If used without this protection, syntax errors can result or implementation extensions can be triggered. For example, the KornShell supports a series of extensions based on parentheses in patterns; see ksh(1) Patterns Matching Multiple Characters The following rules are used to construct patterns matching multiple characters from patterns matching a single character: o The asterisk (*) is a pattern that will match any string, including the null string. o The concatenation of patterns matching a single character is a valid pattern that will match the concatenation of the single characters or collating elements matched by each of the concatenated patterns. o The concatenation of one or more patterns matching a single character with one or more asterisks is a valid pattern. In such patterns, each asterisk will match a string of zero or more characters, matching the greatest possible number of characters that still allows the remainder of the pattern to match the string. Since each asterisk matches zero or more occurrences, the patterns a*b and a**b have identical functionality. Examples: a[bc] matches the strings ab and ac. a*d matches the strings ad, abd and abcd, but not the string abc. a*d* matches the strings ad, abcd, abcdef, aaaad and adddd. *a*d matches the strings ad, abcd, efabcd, aaaad and adddd. Patterns Used for Filename Expansion The rules described so far in Patterns Matching Multiple Characters and Patterns Matching a Single Character are qualified by the following rules that apply when pattern matching notation is used for filename expansion. 1. The slash character in a pathname must be explicitly matched by using one or more slashes in the pattern; it cannot be matched by the asterisk or question-mark special characters or by a bracket expression. Slashes in the pattern are identified before bracket expressions; thus, a slash cannot be included in a pattern bracket expression used for filename expansion. For example, the pattern a[b/c]d will not match such pathnames as abd or a/d. It will only match a pathname of literally a[b/c]d. 2. If a filename begins with a period (.), the period must be explicitly matched by using a period as the first character of the pattern or immediately following a slash character. The leading period will not be matched by: o the asterisk or question-mark special characters o a bracket expression containing a non-matching list, such as: [!a] a range expression, such as: [%-0] or a character class expression, such as: [[:punct:]] It is unspecified whether an explicit period in a bracket expression matching list, such as: [.abc] can match a leading period in a filename. 3. Specified patterns are matched against existing filenames and pathnames, as appropriate. Each component that contains a pat- tern character requires read permission in the directory containing that component. Any component, except the last, that does not contain a pattern character requires search permission. For example, given the pattern: /foo/bar/x*/bam search permission is needed for directories / and foo, search and read permissions are needed for directory bar, and search per- mission is needed for each x* directory. If the pattern matches any existing filenames or pathnames, the pattern will be replaced with those filenames and pathnames, sorted according to the collating sequence in effect in the current locale. If the pattern contains an invalid bracket expres- sion or does not match any existing filenames or pathnames, the pattern string is left unchanged. SEE ALSO
find(1), ksh(1), fnmatch(3C), regex(5) SunOS 5.11 28 Mar 1995 fnmatch(5)
All times are GMT -4. The time now is 03:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy