Sponsored Content
Top Forums Shell Programming and Scripting Bash to copy file 3 times and rename based on another file Post 302992160 by cmccabe on Wednesday 22nd of February 2017 08:13:50 AM
Old 02-22-2017
Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you Smilie.


/home/cmccabe/Desktop/test/list.txt
Code:
analysis done using v1.5 by cmccabe at 02/08/17 12:19:08 PM
patients analyzed: 
00-0000_Last-First
11-1111_LastName-FirstName
22-2222_LastLastName-FirstFirstName

/home/cmccabe/Desktop/list/QC (always a single text file with data in it)
Code:
metrics.txt


Code:
linesToSkip=2
{
    for ((i=$linesToSkip;i--;)) ;do
        read
        done
files=( /home/cmccabe/Desktop/list/QC/metrics.txt )
i=0
while read -r new_name; do
  mv "${files[$i]}" "$new_name"
  (( i++ ))
}
done < /home/cmccabe/Desktop/test/list.txt


Last edited by cmccabe; 02-22-2017 at 09:14 AM.. Reason: fixed format
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

2. Shell Programming and Scripting

copy/rename file as date() unix/shell

File.jpg I want to copy and rename this as 2008-12-02.jpg I tried this copy File.jpg date '%y-%m-%d-%H:%M:%S'.jpg This doesnt work.... what do i do? (1 Reply)
Discussion started by: hdogg
1 Replies

3. Shell Programming and Scripting

Copy 1 file 5000 times and Rename each +1

Hi, Found lots of stuff that is close but no cigar... I have a file ie. a.txt, and I want to copy it to another directory 5000 times and call it: a1.txt a2.txt ... a5000.txt Struggling to put a loop together in this new world of AIX. please include full script for me to understand... (3 Replies)
Discussion started by: terry2009
3 Replies

4. Shell Programming and Scripting

copy and rename file..

hi all, I have one config folder and updates folder.updates folder contains file tmp_2.0_20201208_45.xml and config folder contains file tmp.xml.When the tmp_2.0_20201208_45.xml file is copied in the config folder the name of this file is changed in config folder again as tmp.xml(old... (8 Replies)
Discussion started by: shubhig15
8 Replies

5. Shell Programming and Scripting

.sh file To rename existing file and copy new file

Hi All, I am very new to shell scripting . In my current task i want to create .sh file that will rename the existing file with appending _bu in it. And then copy new file . e.g if i have file linuxFirst.java then i want to rename it to linuxFirst_bu.java ..Then want replace with latest... (1 Reply)
Discussion started by: maheshkaranjkar
1 Replies

6. Shell Programming and Scripting

Rename portion of file based on another file

Hello, I've been searching and reading, but I can't figure out how to solve this problem with my newbie skills. In my directory, I have a list of files (see dirlist.txt attachment) that I need to merge and rename. I have part of the code of the code figured out (see below). However, I... (3 Replies)
Discussion started by: anjulka
3 Replies

7. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

8. Shell Programming and Scripting

Need help in writitng a script to rename file name and copy to other folder

Hi All, My requirement is as follows: A file (say abc) will be having list of the .txt file names. I need to read this abc file line by line and rename the .txt file names inside it and move them to other folder/path. Eg: abc ------- file1.txt file2.txt file3.txt Output (should... (1 Reply)
Discussion started by: pavan.yadalla
1 Replies

9. Shell Programming and Scripting

File Copy based on file receive date

I have bunch of files in my source folder like below and every day based on date I am receiving file ex: Nov 28,Nov 29,Nov 30 ... -rw-rw-r--+ 1 root root 20 Nov 27 06:00 aaaa27.txt -rw-rw-r--+ 1 root root 20 Nov 28 06:00 aaaa28.txt -rw-rw-r--+ 1 root root 20 Nov 29 06:00 aaaa29.txt I... (4 Replies)
Discussion started by: krish2014
4 Replies

10. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies
ODIDX(1)						      Quick Database Manager							  ODIDX(1)

NAME
odidx - indexer of document files SYNOPSIS
odidx register [-l file] [-wmax num] [-tsuf sufs] [-hsuf sufs] name[dir] odidx relate name odidx purge name DESCRIPTION
This manual page documents briefly the odidx commands. The command odidx is a utility for indexing files on the local file system. This command is useful for a full-text search system of a Web site. Supported file format are plain text and HTML. Supported character encoding are US-ASCII and ISO-8859-1. The URI of each document is specified with the path of its file. Attributes named as title and date are given to each documents. When a document is already existing in the database, it is registered if its last modification time is newer, or it is ignored. Modification times are stored in the sub database `_mtime' in the main database directory. Score information are stored in the sub database `_score' in the main database directory. This command is used in the above format. name specifies a database name. dir specifies a directory name. OPTIONS
A summary of options is included below. For a complete description, see the file:///usr/share/doc/qdbm-doc/spex.html#odeumcli. -l file read a file and get list of paths of files to register. If `-' is specified, the standard input is read. -wmax num specify the max number of words to be stored in the document database. -tsuf sufs specify suffixes of plain text files in comma separated format. The default is `-tsuf .txt,.text'. -hsuf sufs specify suffixes of HTML files in comma separated format. The default is `-hsuf .html,.htm'. EXAMPLES
For example, to register files which are under `/home/mikio' and whose suffix are `.txt', `.c', or `.h', perform the following command. odidx register -tsuf ".txt,.c,.h" -hsuf "" casket /home/mikio Thus, to retrieve documents which include `unix' and `posix' and show the top 8 terms, perform the following command. odmgr search -max 8 -h casket "unix posix" SEE ALSO
qdbm(3), odmgr(1), odeum(3), odopen(3). AUTHOR
QDBM was written by Mikio Hirabayashi <mikio@fallabs.com>. This manual page was written by Fumitoshi UKAI <ukai@debian.or.jp>, for the Debian project (but may be used by others). Man Page 2005-05-23 ODIDX(1)
All times are GMT -4. The time now is 09:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy