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
wordexp(3)						     Library Functions Manual							wordexp(3)

NAME
wordexp, wordfree - Perform word expansions LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <wordexp.h> int wordexp( const char *words, wordexp_t *pwordexp, int flags); void wordfree( wordexp_t *pwordexp); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: wordexp(), wordfree(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the string containing the tokens to be expanded. Contains a pointer to a wordexp_t structure. Contains a bit flag specifying the configurable aspects of the wordexp() function. DESCRIPTION
The wordexp() function performs word expansions equivalent to the word expansion that would be performed by the shell if the contents of the words parameter were arguments on the command line. The list of expanded words are placed in the pwordexp parameter. The expansions are the same as that which would be performed by the shell if the words parameter were the part of a command line represent- ing the parameters to a command. Therefore, the words parameter cannot contain an unquoted newline character or any of the unquoted shell special characters: | & ; < > except in the case of command substitution. The words parameter also cannot contain unquoted parentheses or braces, except in the case of command or variable substitution. If the words parameter contains an unquoted comment character (#) that is the beginning of a token, the wordexp() function may treat the comment character as a regular character, or may interpret it as a comment indicator and ignore the remainder of the expression in the words parameter. The wordexp() function stores the number of generated words and a pointer to a list of pointers to words in the pwordexp parameter. Each individual field created during the field splitting or pathname expansion is a separate word in the list specified by the pwordexp parame- ter. The first pointer after the last token in the list is a null pointer. The expansion of special parameters *, @, #, ?, -, $, !, and 0 is unspecified. The words are expanded in the following order: Tilde expansion is performed first. Parameter expansion, command substitu- tion, and arithmetic expansion are performed next, from beginning to end. Field splitting is then performed on fields generated by step 2, unless the IFS (Input Field Separators) is full. Pathname expansion is performed, unless the set -f command is in effect. Quote removal is always performed last. The pwordexp structure is allocated by the caller, but memory to contain the expanded tokens is allocated by the wordexp() function and added to the structure as needed. The wordfree() function frees any memory associated with pwordexp() from a previous call to wordexp(). The value of the flags parameter is the bitwise inclusive OR of the following constants, which are defined in the wordexp.h file: Appends words generated to those generated by a previous call to the wordexp() function. Makes use of the we_offs structure. If the WRDE_DOOFFS flag is set, the we_offs structure is used to specify the number of null pointers to add to the beginning of the we_words structure. If the WRDE_DOOFFS flag is not set in the first call to the wordexp() function with the pwordexp parameter, it should not be set in subsequent calls to the wordexp() function with the pwordexp parameter. Fails if command substitution is requested. The pwordexp parameter was passed to a previous successful call to the wordexp() function. Therefore, the memory previously allocated may be reused. Does not redi- rect standard error to /dev/null. Reports error on an attempt to expand an undefined shell variable. The WRDE_APPEND flag can be used to append a new set of words to those generated by a previous call to the wordexp() function. The follow- ing rules apply when two or more calls to the wordexp() function are made with the same value of the pwordexp parameter and without inter- vening calls to the wordfree() function: The first such call does not set the WRDE_APPEND flag. All subsequent calls set it. For a single invocation of the wordexp() function, all calls either set the WRDE_DOOFFS flag, or do not set it. After the second and each subsequent call, the pwordexp parameter points to a list containing the following: Zero or more null characters, as specified by the WRDE_DOOFFS flag and the we_offs field of the wordexp_t structure. Pointers to the words that were in the pwordexp parameter before the call, in the same order as before. Pointers to the new words generated by the latest call, in the specified order. The count returned in the pwordexp parameter is the total number of words from all of the calls. The application should not modify the pwordexp parameter between the calls. Unless the WRDE_SHOWERR flag is set in the flags parameter, the wordexp() function redirects standard error to /dev/null for any utilities executed as a result of command substitution while expanding the words parameter. If the WRDE_SHOWERR flag is set, the wordexp() function can write messages to standard error if syntax errors are detected while expanding the words parameter. If any of the following conditions occurs, the wordexp() function returns the corresponding nonzero constant, which is defined in the word- exp.h file. One of the unquoted characters |, & , ;, <, >, newline, parenthesis, or braces appears in the words parameter in an inappro- priate context. Reference to undefined shell variable when the WRDE_UNDEF flag is set in the flags parameter. Command substitution requested when the WRDE_NOCMD flag is set in the flags parameter. An attempt to allocate memory was unsuccessful. Shell syntax error, such as unbalanced parentheses or unterminated string. The wordexp() function allows an application to perform all of the shell's expansions on a word or words obtained from a user. For example, if the application prompts for a filename (or a list of file names) and then uses the wordexp() function to process the input, the user could respond with anything that would be valid as input to the shell. The WRDE_NOCMD flag is provided for applications that, for security or other reasons, want to prevent a user from executing shell commands. Disallowing unquoted shell special characters also prevents unwanted side effects such as executing a command or writing to a file. NOTES
The wordexp() function can cause a signal to be issued. If a user program catches the signal, wordexp() may return an error. FILES
Defines word expansion macros, data types, and functions. RETURN VALUES
If no errors are encountered while expanding the words parameter, the wordexp() function returns a value of 0 (zero). If an error occurs, the function returns a nonzero value indicating the error. If the wordexp() function returns the error value WRDE_NOSPACE, then the expression in the pwordexp parameter is updated to reflect any words that were successfully expanded. In other cases, the pwordexp parameter is not modified. The wordfree() function returns no value. RELATED INFORMATION
Functions: glob(3) Standards: standards(5) delim off wordexp(3)
All times are GMT -4. The time now is 10:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy