Sponsored Content
Top Forums Shell Programming and Scripting File renaming from list of names contained in another file Post 302433259 by netfreighter on Tuesday 29th of June 2010 05:34:05 AM
Old 06-29-2010
Quote:
Originally Posted by bartus11
This should work:
Code:
awk '{f=$1;sub("-.*\\.","_"$2".",$1);system("mv "f" "$1)}' file-with-filenames

works like a charm!

very subtle! it replaces the dashes with underscore and renames the files with the number supplied in the right column.
many, many thanks!!!

may I ask you what the "system" command or call does? is it like $(command)?
anyway, thank you, very grateful.
 

10 More Discussions You Might Find Interesting

1. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

2. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies

3. Shell Programming and Scripting

Renaming file names

I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (2 Replies)
Discussion started by: vpv0002
2 Replies

4. Shell Programming and Scripting

List of file names

I have the following list of file names stored in $fnames, so that if I do foreach f ($fnames) echo "$f" end I will get n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run1 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run2 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run3... (3 Replies)
Discussion started by: kristinu
3 Replies

5. UNIX for Dummies Questions & Answers

Renaming files in one file from names in other

Hi Guys, I have a small problem of renaming multiple files. For example I have names of a set of files in one directory like K2_34625-34675 K7_988963-988983 K12_773882-7734102 and the other set corresponding to the same is U_P_321_9_3_11.ab1 U_P_322_9_3_11.ab1 U_P_323_9_3_11.ab1 Now... (23 Replies)
Discussion started by: pawannoel
23 Replies

6. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

7. Shell Programming and Scripting

Renaming File Names in a folder/Dir

Hi Team, I'm new to Unix shell scripting . I've the following requirement A folder contains the list of files with the following format ab.name.11.first ab.name.12.second ab.name.13.third ---------- I have to rename the above file to like below ... (6 Replies)
Discussion started by: smile689
6 Replies

8. Shell Programming and Scripting

List the file names available on FTP server before selecting the required file

Below is my script code.which shows the environment name and then fetch the file from the ftp server but I am facing one issue.The script should be run in both way.We can pass the arguments with script and select the environment name then file name.Here the issue is I am not able to list the files... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

9. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

10. UNIX for Beginners Questions & Answers

Renaming the file names in a directory

Hi, I have about 60 files in a directory and need to rename those files. For example the file names are i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc) i_usa_phone_1_yymmdd.txt i_eng_phone_4_yymmdd.txt The new file names should be phone.txt phone_1.txt phone_4.txt I am... (4 Replies)
Discussion started by: naveed
4 Replies
NCRENAME(1)						      General Commands Manual						       NCRENAME(1)

NAME
ncrename - netCDF Renamer SYNTAX
ncrename [-a old_name,new_name] [-a ... ] [-D] [-d old_name,new_name] [-d ... ] [-h] [-l path] [-O] [-p path] [-R] [-r] [-v old_name,new_name] [-v ... ] input-file [ output-file] DESCRIPTION
ncrename renames dimensions, variables, and attributes in a netCDF file. Each object that has a name in the list of old names is renamed using the corresponding name in the list of new names. All the new names must be unique. Every old name must exist in the input file, unless the name is preceded by the character .. The validity of the old names is not checked prior to the renaming. Thus, if an old name is specified without the the . prefix and is not present in input-file, ncrename will abort. ncrename is the exception to the normal rules that the user will be interactively prompted before an existing file is changed, and that a temporary copy of an output file is constructed during the operation. If only input-file is specified, then ncrename will change the names of the input-file in place without prompting and without creating a temporary copy of input-file. This is because the renaming operation is considered reversible if the user makes a mistake. The new_name can easily be changed back to old_name by using ncrename one more time. Note that renaming a dimension to the name of a dependent variable can be used to invert the relationship between an independent coordinate variable and a dependent variable. In this case, the named dependent variable must be one-dimensional and should have no missing values. Such a variable will become a coordinate variable. According to the netCDF User's Guide, renaming properties in netCDF files does not incur the penalty of recopying the entire file when the new_name is shorter than the old_name. OPTIONS
-a old_name, new_name Attribute renaming. The old and new names of the attribute are specified by the associated old_name and new_name values. Global attributes are treated no differently than variable attributes. This option may be specified more than once. You cannot change the attribute name for one particular variable (unless it is uniquely named); all occurrences of the attribute of a given name will be renamed. This is considered an oversight and will be addressed in a future version of NCO. -d old_name, new_name Dimension renaming. The old and new names of the dimension are specified by the associated old_name and new_name values. This option may be specified more than once. -v old_name, new_name Variable renaming. The old and new names of the variable are specified by the associated old_name and new_name values. This option may be specified more than once. -i Interactive. ncrename will prompt for confirmation before overwriting an existing file. EXAMPLES
Rename the variable p to pressure and t to temperature in netCDF in.nc. In this case p must exist in the input file (or ncrename will abort), but the presence of t is optional: ncrename -v p,pressure -v .t,temperature in.nc ncrename does not automatically attach dimensions to variables of the same name. If you want to rename a coordinate variable so that it remains a coordinate variable, you must separately rename both the dimension and the variable: ncrename -d lon,longitude -v lon,longitude in.nc Create netCDF out.nc identical to in.nc except the attribute _FillValue is changed to missing_value (in all variables which possess it) and the global attribute Zaire is changed to Congo: ncrename -a _FillValue,missing_value -a Zaire,Congo in.nc out.nc AUTHOR
NCO manual pages written by Charlie Zender and Brian Mays. REPORTING BUGS
Report bugs to <http://sf.net/bugs/?group_id=3331>. COPYRIGHT
Copyright (C) 1995-2011 Charlie Zender This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for NCO is maintained as a Texinfo manual called the NCO User's Guide. Because NCO is mathematical in nature, the documentation includes TeX-intensive portions not viewable on character-based displays. Hence the only complete and authoritative versions of the NCO User's Guide are the PDF (recommended), DVI, and Postscript versions at <http://nco.sf.net/nco.pdf>, <http://nco.sf.net/nco.dvi>, and <http://nco.sf.net/nco.ps>, respectively. HTML and XML versions are available at <http://nco.sf.net/nco.html> and <http://nco.sf.net/nco.xml>, respectively. If the info and NCO programs are properly installed at your site, the command info nco should give you access to the complete manual, except for the TeX-intensive portions. HOMEPAGE
The NCO homepage at <http://nco.sf.net> contains more information. NCRENAME(1)
All times are GMT -4. The time now is 10:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy