identify files with "Normal termination" and compress them into a .tar.gz file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting identify files with "Normal termination" and compress them into a .tar.gz file
# 1  
Old 03-18-2011
identify files with "Normal termination" and compress them into a .tar.gz file

Hi,

I have hundreds of files "*.out" located in one folder,
and I want to:
1. Identify the good files containing "Normal termination" (grep "Normal termination" *.out )
2. Compress the good files into a tar.gz file (tar cvfz good.tar.gz *.goog.out )

Is there a way I can automate this process using a shell script?

Thanks!
Todd
# 2  
Old 03-18-2011
Here is a start

Code:
grep -F "Normal termination" *.out | cut -d':' -f1 | sort | uniq

will provide a list of files that meet that condition
# 3  
Old 03-18-2011
maybe something like
Code:
grep -l "Normal termination" /your_folder/*.out 2>/dev/null | xargs tar cvfz your_archive.tar

or
Code:
cd /your_folder/ && grep -l "Normal termination" ./*.out 2>/dev/null | xargs tar cvfz your_archive.tar

# 4  
Old 03-18-2011
Elaborating on ctsgnb you could compress the tar file in the same command:-
Code:
grep -l "Normal termination" /your_folder/*.out 2>/dev/null |tar cvf - |compress> your_archive.tar.Z

This should work if the z flag is not supported by your operating system.

If there are too many files for the grep to cope with (i.e. if *.out expands to build a command line of more than the maximum command length for your operating system) you could convert to find however this would decend any subdirectories and follow symbolic links. Another problem you may hit would be that the list of files generated could be longer that would fit one command for the tar part. Using xargs may cause you to backup over the same file several times. Smilie You would end up with a file of only the last groups written to the archive.

If you have AIX, you can capture the file names in another file then use that with the -L flag, but I'm not sure which other operating systems support this.

The command found become two lines:-
Code:
find . -type f -name "*.out" -exec grep -l "Normal Termination" {} /dev/null \; >/tmp/filelist 2>/dev/null
tar -cvf - -L /tmp/filelist|compress>your_archive.tar.Z


I hope that this helps


Robin
Liverpool/Blackburn
UK

Last edited by rbatte1; 03-18-2011 at 02:48 PM..
# 5  
Old 03-18-2011
Thanks so much!
Combining you three's solutions, it works perfectly!
Have a good day!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Please identify "unexpected end of file" bug

This is a script I got off the web for transferring Safari's "reading list" to the Pocket app. I ran it in terminal with the command bash exportsafarireadinglist.sh and got syntax error: unexpected end of file. Thanks for any help! The code: #!/bin/bash # Script to export Safari's reading... (2 Replies)
Discussion started by: kdog126
2 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Advanced & Expert Users

Trace "free(): invalid next size (normal)" error on arm-linux board

Hi guys, i'm running a program on samsumg 6410 arm cpu board. it caused an "free(): invalid next size (normal)" fail. i try to use gdb for remote debugging: 1, start gdb server on board: gdbserver 192.168.1.20:1234 ./HostAP Process ./HostAP created; pid = 499 Listening on port... (8 Replies)
Discussion started by: ss1969
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Identify high values "˙" in a text file using Unix command

I have high values (such as ˙˙˙˙) in a text file contained in an Unix AIX server. I need to identify all the records which are having these high values and also get the position/column number in the record structure if possible. Is there any Unix command by which this can be done to : 1.... (5 Replies)
Discussion started by: devina
5 Replies

7. HP-UX

Need to identify the process/app which is triggering the error "vmunix: file: table is full"

Hi, I'm seeing the error vmunix: file: table is full in syslog.log. Although changing the value of the kernel parameter nfile would make this error go away, how would I identify which process/application in the server is triggering this error? The server is a HP-UX B.11.11. Thanks in advance! (1 Reply)
Discussion started by: enchogas
1 Replies

8. AIX

aix 4.2 "compress" : any issues with files bigger then 1Gig ?

To speed up our backups, I found a way to compress all the backups files without running out of space. But before starting to use this in our procedures, I want to know if the command 'compress' has any issues in AIX 4.2 with files bigger then 1Gig. Our backup files have sizes ranging between 600Mg... (1 Reply)
Discussion started by: Browser_ice
1 Replies

9. UNIX for Dummies Questions & Answers

using Tar -cvf file.tar "Need Help"

Ok, I use the command tar -cvf ~kw4691/output/test.tar ~kw4691/input on one UNIX server, lets call it sneezy. I FTP the tared file over to another server, lets call it bashful. Use the tar -xvf test.tar command and get the error ~kw4691/input "could not create the directory" /hom/dev/sy40... (7 Replies)
Discussion started by: wev
7 Replies

10. UNIX for Dummies Questions & Answers

"File in use" - how to identify locks on this file and release them?

At times we see the "file in use" when we run RCS (revision conrol system" on this file. Most of time, we do not see this message. How do we identify the locks on this file and how do we release those locks? I can imagine it happens when there are some processes running on this file. THe... (1 Reply)
Discussion started by: vadimsf
1 Replies
Login or Register to Ask a Question