ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
need to above red color as validation and then move those files only .
again explaining .
On daily base high not of files coming where time stamp is current data but files coming from source which has old data as mark in above red , we need to identified and print and then if correct output then move to other location need your input on above .
Few more sample files .
with 2015 and 2014 both date (2015062900 & 2014062900)
that was the link I gave you. You just need to implement your conditions. You can do something like this:
if ( $3 > "some date" ) { print ("mv s, %s", $0, "some dir") | "sh" }
(not tested)
pan64 has given you a good clue for inner comparison BUT you have to read carefully AND ALSO put effort to write full code for 2 comparisons ($3 within $9)
As I understand, ninth field (as per post #3) gives the file name from which you have to compare on third field which has actual creation date.
So if the date to be selected is 20140627, then I might go
ls -rtl | awk '{printf("s^%s\n", $9, $0}' | awk -F. '{if($3=="2014062700") print $0}' | awk -F^ '{printf("mv %s dest/dir/path\n", $2}' >> mover.sh
Explanation:
First awk prints ninth field of original file (as you have done) PLUS writes a carat character ^PLUS original file name.
Second awk uses selects only those matching required date.
Third awk removes column 1 (which contains selection information only).
Now mover.sh should have a series of mv commands which you can run with sh command. Also till you are sure of the correct output you need not run mover.sh
above three files first file hid_160_9_176_8.ejmedia then Date 2014062700 which is old date which will be any date not fix those files need to identified with today date - 10 days and move to other location that is the exception of the out put .
hope i am able to communicate my issue properly still gap let me know your understanding .
Please remember back date will be change it should be 2014 or 2013 or any month and any date those files need to move base on file name .
then move is not correct exception . my issue is that i am receiving old files which not specific date it will be any date which is name format will be like below i need to identified old files with name of the files and move to them from huge list of files . as sample below .
above three files first file hid_160_9_176_8.ejmedia then Date 2014062700 which is old date which will be any date not fix those files need to identified with today date - 10 days and move to other location that is the exception of the out put .
hope i am able to communicate my issue properly still gap let me know your understanding .
Please remember back date will be change it should be 2014 or 2013 or any month and any date those files need to move base on file name .
We understand your issue fine...but what I can't understand is why you cannot take the examples and information you've been handed, and actually try something of your own, rather than asking us to fix it for you.
Can you show us what YOU have done/tried to get this working?
@OP:
Off: I think you should make some effort on your own
On: Here is a script that might give you some ideas
Code:
#!/bin/sh
LIMIT00=$(date -d '111 days ago' +'Y%m%d00')
for i in hid*; do
printf '%s\n' "$i" | (
IFS=. read UNUSED UNUSED DATUM00 UNUSED
if [ "$DATUM00" -lt "$LIMIT00" ]; then
printf 'Wow %s *is* old\n' "$i"
else
printf 'Wow %s is not too old\n' "$i"
fi
)
done
but i have tested above script not giving current out put .
Wow hid_160_8_128_2.ejmngrcmd.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejmngrcmd.2015070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejpromo.2015062900.1435606413.1435606413.xml is not too old
Wow hid_160_8_128_2.ejpromo.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejpromo.2015070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejstorerecall.2015062900.1435606413.1435606413.xml is not too old
Wow hid_160_8_128_2.ejstorerecall.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejstorerecall.2015070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejsubtotal.2015062900.1435606413.1435606413.xml is not too old
Wow hid_160_8_128_2.ejsubtotal.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejsubtotal.2015070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejsupint.2015062900.1435606413.1435606413.xml is not too old
Wow hid_160_8_128_2.ejsupint.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejsupint.2015070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejtrailer.2015062900.1435606413.1435606413.xml is not too old
Wow hid_160_8_128_2.ejtrailer.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejtrailer.2015070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejuserstruct1.2015062900.1435606413.1435606413.xml is not too old
Wow hid_160_8_128_2.ejuserstruct1.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejuserstruct1.2015070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejuserstruct2.2014070100.1435779263.1435779263.xml is not too old
Wow hid_160_8_128_2.ejuserstruct2.2015062900.1435606413.1435606413.xml is not too old
Wow hid_160_8_128_2.ejuserstruct2.2015063000.1435692730.1435692730.xml is not too old
Wow hid_160_8_128_2.ejuserstruct2.2015070100.1435779263.1435779263.xml is not too old
Above mark in red is old files 2014070100 but out put showing is not too old .
as it was already mentioned:
1. Here is a script that might give you some ideas
2. actually try something of your own, rather than asking us to fix it for you
and now add set -xv at the beginning of your script and you will see what's happening (that will not solve anything, just print a lot about how it works)
for i in hid*; do
printf 's\n' "$i" | (
IFS=. read UNUSED UNUSED DATUM00 UNUSED
echo $LIMIT00
echo $DATUM00
if [ "$DATUM00" -lt "$LIMIT00" ]; then
printf 'Wow %s *is* old\n' "$i"
else
printf 'Wow %s is not too old\n' "$i"
fi
)
done
----------------------------------
Out put showing wrong .
2014010100
2015063000
Wow hid_160_8_128_2.ejuserstruct1.2015063000.1435692730.1435692730.xml is not too old
2014010100
2015070100
Wow hid_160_8_128_2.ejuserstruct1.2015070100.1435779263.1435779263.xml is not too old
2014010100
2015070200
Wow hid_160_8_128_2.ejuserstruct1.2015070200.1435865525.1435865525.xml is not too old
2014010100
2014070100
Wow hid_160_8_128_2.ejuserstruct2.2014070100.1435779263.1435779263.xml is not too old
2014010100
2015063000
Wow hid_160_8_128_2.ejuserstruct2.2015063000.1435692730.1435692730.xml is not too old
2014010100
2015070100
Wow hid_160_8_128_2.ejuserstruct2.2015070100.1435779263.1435779263.xml is not too old
2014010100
2015070200
Wow hid_160_8_128_2.ejuserstruct2.2015070200.1435865525.1435865525.xml is not too old
2014010100 < 2014070100
As per script it should be out put " Wow %s *is* old\n'" but it is giving wrong so please help on above .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.