Instead of using date and awk and cut, I'd just use date and shell built-ins:
Note that the code you have will print 1 digit years instead of 2 digit years starting in years 01 through 10 in each century. Note also that date +%y would also work with ksh; but would give you a syntax error in years 08 and 09 in each century if you're using bash.
could plz explain code why u using two ((($(date +%Y) + 99) % 100)))" bracket
I don't know what you mean about using two bracket. There are no brackets; only parentheses. The command I suggested:
uses a command substitution inside double quotes using printf to format the name of the destination file operand for the mv command. That accounts for the "$( at the start of that operand and the )" at the end of that operand. The command being run in that command substitution is a printf command with a single quoted format argument of 'XYP.ZAT%02d.PGPNX.TRDIY' where the text other than the %02d is the constant part of the destination filename you specified and the %02d is a format specifier requesting that a decimal value of two or more digits be printed using a leading 0 if the number to be printed is less than 10. The remaining text:
is an arithmetic substitution ($(( expression ))) where the expression being processed is:
which adds 99 to the result of another command substitution ($(date +%Y) which invokes the date utility to get the complete current year) and then returns the remainder of dividing that sum by 100. That result will be a one or two digit decimal number in the inclusive range 0 through 99 (which will be the last two digits of the previous year).
Note that when I first started trying to come up with a way to do this, I was using %y instead of %Y as the date utility format specifier (which just returns the last two digits of the current year instead of the entire year) so I added 99 instead of subtracting 1 to avoid getting a negative value for the mod operation in cases where the script might be run in a year ending in 00. Since the script is now using %Y, you could get exactly the same results with:
if the 99 is confusing you. And if having the parentheses for the various operations next to each other is confusing to you, you can add spaces separating the operators if it makes it easier for you to read:
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 :).
... (12 Replies)
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)
I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this?
... (12 Replies)
Hi,
i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file..
ex..
File.txt
1236 43715825601ANDERSSON,
1236 437158256031963040120060901200609010000000
1236 43715825604123 MCCL AVE UPPER
1236 ... (11 Replies)
how to rename a file if I don't know file location ?
Can we below command :
$ find / | mv file1.txt
I am not sure........can any1 help me out ?
Thanks,
Tushar Joshi:mad: (1 Reply)
dear all,
i have case with this:
i have file 20110601.txt so i want to auto rename this file like this 20110601_20110602.txt
actual this rename will create if 20110601 came in date 20110602(date from system unix)
so this will be using
#!/bin/bash
folder='/home'
desti='/home/desti'... (2 Replies)
Hello all.
I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b:
I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused:
I have all of my music stored in... (7 Replies)
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)
Hi,
I am getting a file name from a remote server thru ftp and storing this filename in a variable. I am doing this in ftp mode.
for ex: the filename is like emp_010208.
This file name has to be changed to emp.
Can you please let me know how we can do this while we are in ftp mode.
thanks,... (0 Replies)
Hi there,
I hope someone can help me with this problem :
I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus :
prefix-date-key-suffix.jpg
they all have the prefix p-20050608-
then AAAA is a 4 letter code
the suffix is... (7 Replies)