experts I have many text files in a directory named as file1.txt, file2.txt file3.txt.... file100.txt attached here. Moreover, the structure of the data in all the files is given below, where first column represent dates, second column is hr:mn:sec and the third column is extra info which i don't want to use.
file1.txt
2019-01-01 06:22:22.345000 12.08 sec
2019-01-01 08:13:08.235000 6.14 sec
2019-01-01 14:37:47 6.36 sec
2019-01-01 17:57:32.385000 5.91 sec
2019-01-01 18:34:00.905000 18.35 sec
2019-01-02 02:39:17 6.44 sec
2019-01-02 02:39:46.365000 6.26 sec
2019-01-02 12:36:48.995000 17.37 sec
.....................................
.....................................
2019-05-21 03:52:39.415000 4.92 sec
Most importantly, in some files there is some data; like it may start in the middle of may and ends only after 10/15 days, but the structure of the data is same as above.
What I want to do is:
From file to file, At first i want to match the date, if the date matches, then i want to match hour if the hour matches, then i want to match minute and if the minute matches i want to match seconds. If the difference in seconds between the two lies within 0 to 5 seconds I want to extract that whole line and want to save it in a autogenerated text file notnecessary.txt
suppose from the file1.txt(attached above) "2019-01-01 06:22:22.345000 12.08 sec" fall within that condition then it should be deleted from the original file(file1.txt) and saved inside notnecessay.txt as "2019-01-01 06:22:22.345000 12.08 sec file1.txt"
I tried the script, but fail to do the same as it is little bit tricky
#!/bin/sh
for file in /home/chunmun/data/*.txt
do
echo $file
if [ $file = $file ];
then
mv -v $file /home/chunmun/ext
fi
done
Please suggest a solution.Thanks.
Aucun commentaire:
Enregistrer un commentaire