Move a TXT file greater or equal 355 MB with its corresponding .LST file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Move a TXT file greater or equal 355 MB with its corresponding .LST file
# 1  
Old 01-25-2020
Move a TXT file greater or equal 355 MB with its corresponding .LST file

Good morning, i need your help please
I need to move a .TXT file greater or igual 355 MB and its correspondent .LST file in a non recursive way

The operating system is:

Code:
uname -a
SunOS server01c 5.10 Generic_144488-01 sun4u sparc SUNW,SPARC-Enterprise

For example:

Code:
rw-r--r--   1 xptol    explotacion    355M Jan 25 03:54 NS6142SCA20200125033624.TXT
-rw-r--r--   1 xptol    explotacion       7 Jan 25 03:54 NS6142SCA20200125033624.LST

I could identify the file with the find command

Code:
find . ! -name . -prune -name 'NS6142*' -size +355000000c -print

Output;
Code:
NS6142SCA20200125033624.TXT

because every file is transmitted ever 20 minutes i need to loop but i dont know how to get around to move the 355 MB .TXT file which its correspondebt .LST file

Code:
while true
do
 sleep 2400
 find . ! -name . -prune -name 'NS6142*' -size +355000000c -exec mv {} target_dir \; 
 --identify .lST file and move to target_dir
done

or is there a better way to get around this, i wiil appreciate your help

Thanks for your help in advanced
# 2  
Old 01-25-2020
You can store the filename in a variable and construct the other filename from it.
In case it finds more than one filename use a for loop or while loop:
Code:
#!/bin/bash
while true
do
 sleep 2400
 # find big .TXT files
 find . ! -name . -prune -name 'NS6142*.TXT' -size +355000000c -print |
 # raw-read the filenames from the pipe
 while IFS= read -r fn
 do
  # strip .TXT and add .LST
  fn2=${fn%.TXT}.LST
  # move both files to target_dir
  mv "$fn" "$fn2" target_dir
 done
done

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 01-25-2020
Hi
Quote:
Originally Posted by alexcol
...
Code:
find . ! -name . -prune -name 'NS6142*' -size +355000000c -print

...
And it will not be the same thing without a leading current directory?
Code:
find * -prune -name 'NS6142*'

# 4  
Old 01-25-2020
Thank you very much for your help, I tested the script and its working properly, could u mind explain me briefly these lines:

Code:
 while IFS= read -r fn

loop ?

Code:
 fn2=${fn%.TXT}.LST

var ?

Thanks for your help in advenced
# 5  
Old 01-26-2020
I gave brief explanations as comments in the code.
The following are comprehensive ones:

while condition - do - done
is a loop. The condition is the read command that reads a line from the standard input (here: the pipe i.e. the output from the previous command); the exit status is 0 (true) if the read could read something, then the loop continues, trying to read the next line. Finally, if nothing can be read, the exit code is not 0 (false) and the loop ends.
The read fn command reads the line into the fn variable. By default it strips leading spaces from the input; this is prevented by temporary setting the environment variable IFS to nothing. Further, read by default does special treatment with \ characters in the input; this behavior is turned off with the -r option.
(Compare this loop with the other loop where condition is always true so it never ends.)

The fn2 variable is assigned a string that is a concatenation of ${fn%.TXT} and .LST. The first is the value from variable fn with a modifier. The % modifier strips the following pattern from the end. (Compare with an unmodified value ${fn} (that is in short $fn).)
These 3 Users Gave Thanks to MadeInGermany For This Post:
# 6  
Old 01-26-2020
Thanks you very much again for your help and explanation, it was really useful
# 7  
Old 01-27-2020
One final question please:
Script did what is supposed to do but I came up a question related what you mentioned previusly:
Compare this loop with the other loop where condition is always true so it never ends

So this script is supposed to end when the condition is true?
I run the scrpt but never ended

Code:
#!/bin/bash
while true
do
 # find big .TXT files
 find . ! -name . -prune -name 'NS6142*.TXT' -size +355000000c -print |
 # raw-read the filenames from the pipe
 while IFS= read -r fn
 do
  # strip .TXT and add .LST
  fn2=${fn%.TXT}.LST
  # move both files to target_dir
  mv "$fn" "$fn2" ./pruebas/
 done
 sleep 120 
done

Output:

Code:
/produccion/explotacion/xptol/tel/tasacion/RECEP/CENTRAL_142_24012020/pruebas # ls -lrth
total 2909256
-rw-r--r--   1 xptol    explotacion    355M Jan 24 15:40 NS6142SCA20200124152445.TXT
-rw-r--r--   1 xptol    explotacion       7 Jan 24 15:40 NS6142SCA20200124152445.LST
-rw-r--r--   1 xptol    explotacion    355M Jan 24 16:48 NS6142SCA20200124163227.TXT
-rw-r--r--   1 xptol    explotacion       7 Jan 24 16:48 NS6142SCA20200124163227.LST
-rw-r--r--   1 xptol    explotacion    355M Jan 25 01:27 NS6142SCA20200125011130.TXT
-rw-r--r--   1 xptol    explotacion       7 Jan 25 01:27 NS6142SCA20200125011130.LST
-rw-r--r--   1 xptol    explotacion    355M Jan 25 10:39 NS6142SCA20200125102126.TXT
-rw-r--r--   1 xptol    explotacion       7 Jan 25 10:39 NS6142SCA20200125102126.LST

source directory:
Code:
/produccion/explotacion/xptol/tel/tasacion/RECEP/CENTRAL_142_24012020 # ls -lrt|head
total 4249458
-rw-r--r--   1 xptol    explotacion 41016367 Jan 24 14:44 NS6142SCA20200124143011.TXT.gz
-rw-r--r--   1 xptol    explotacion      55 Jan 24 14:44 NS6142SCA20200124143011.LST.gz
-rw-r--r--   1 xptol    explotacion 41016367 Jan 24 15:02 NS6142SCA20200124144828.TXT.gz
-rw-r--r--   1 xptol    explotacion      55 Jan 24 15:02 NS6142SCA20200124144828.LST.gz
-rw-r--r--   1 xptol    explotacion 41016367 Jan 24 15:20 NS6142SCA20200124150634.TXT.gz
-rw-r--r--   1 xptol    explotacion      55 Jan 24 15:20 NS6142SCA20200124150634.LST.gz
-rw-r--r--   1 xptol    explotacion 41016367 Jan 24 16:01 NS6142SCA20200124154443.TXT.gz
-rw-r--r--   1 xptol    explotacion      55 Jan 24 16:01 NS6142SCA20200124154443.LST.gz
-rw-r--r--   1 xptol    explotacion 41016367 Jan 24 17:08 NS6142SCA20200124165229.TXT.gz
/produccion/explotacion/xptol/tel/tasacion/RECEP/CENTRAL_142_24012020 # 
/produccion/explotacion/xptol/tel/tasacion/RECEP/CENTRAL_142_24012020 # ls -lrt|tail
-rw-r--r--   1 xptol    explotacion 41016367 Jan 25 09:56 NS6142SCA20200125093943.TXT.gz
-rw-r--r--   1 xptol    explotacion      55 Jan 25 09:56 NS6142SCA20200125093943.LST.gz
-rw-r--r--   1 xptol    explotacion 41016367 Jan 25 10:16 NS6142SCA20200125100137.TXT.gz
-rw-r--r--   1 xptol    explotacion      55 Jan 25 10:16 NS6142SCA20200125100137.LST.gz
-rw-r--r--   1 xptol    explotacion 41016367 Jan 25 10:59 NS6142SCA20200125104305.TXT.gz
-rw-r--r--   1 xptol    explotacion      55 Jan 25 10:59 NS6142SCA20200125104305.LST.gz
-rw-r--r--   1 xptol    explotacion   10213 Jan 26 23:49 ejemplo.txt
-rwxr-xr-x   1 xptol    explotacion     457 Jan 27 01:39 script1.sh
-rwxr-xr-x   1 xptol    explotacion     488 Jan 27 02:00 script.sh
drwxr-sr-x   2 xptol    explotacion     512 Jan 27 02:01 pruebas/

Thans for your help in advanced
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare first column from two csv files with greater than or equal, and less than

I have two csv files of different sizes. The output file needs to have file1 contents on top of file2 contents where file2 col1 is >= to file1 col1, and file2 col1(same value) is < file1 col1 (next value). So basically, some file2 rows will be matched to the same file1 row because it is the closet... (7 Replies)
Discussion started by: aachave1
7 Replies

2. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

3. UNIX for Dummies Questions & Answers

look for file size greater than "0" of specific pattern and move those to another directory

Hi , i have some files of specific pattern ...i need to look for files which are having size greater than zero and move those files to another directory.. Ex... abc_0702, abc_0709, abc_782 abc_1234 ...etc need to find out which is having the size >0 and move those to target directory..... (7 Replies)
Discussion started by: dssyadav
7 Replies

4. UNIX for Dummies Questions & Answers

Missing menu.lst file in Ubuntu

I am not able to find menu.lst in /boot. During the Linux Kernel Compilation I installed the kernel using make install. Next I created an initrd image. I had to modify the Grub configuration file - /boot/grub/menu.lst which I am not able to find. Any resolution for the issue? (3 Replies)
Discussion started by: rupeshkp728
3 Replies

5. UNIX for Dummies Questions & Answers

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
Discussion started by: johannd
7 Replies

6. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

7. Shell Programming and Scripting

Problem with Greater Than Or Equal To

BASH problem with IS GREATER THAN OR EQUAL TO. I have tried a dozen variations for this IF statement to work with IS GREATER THAN OR EQUAL TO. My code below WORKS. array=( $( /usr/bin/sar -q 1 30 |grep Average |awk '{print $2,$3}' ) ) nthreads="${array}" avproc="${array}" if && ; then ... (6 Replies)
Discussion started by: diex
6 Replies

8. Shell Programming and Scripting

Trying to find files equal to and greater than

Hi Guys and Gals, I'm having some difficulty putting this check into a shell script. I would like to search a particular directory for a number of files. The logic I have is pretty simple: Find file named *.txt that are newer than <this file> and count them If the number of files is equal to... (4 Replies)
Discussion started by: bbbngowc
4 Replies

9. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies

10. Shell Programming and Scripting

Perl how to move pointer to previous line in a txt file?

I have a text file that has blocks of text. Each block starts with ### and ends with End_###. I wrote a perl script to search a string from line 2 (ignore any line starts with ###) of each block if matched, need to print that whole block. According to the input file in below, it will print... (5 Replies)
Discussion started by: tqlam
5 Replies
Login or Register to Ask a Question