Restricting the merged file size to 1 GB


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Restricting the merged file size to 1 GB
# 1  
Old 12-16-2011
Restricting the merged file size to 1 GB

I am working on a problem in which I need to merge 4 files (say f1,f2,f3 & f4 log files) & then prepare a final file.

1) If the final file created has size more than 1 GB then need to throw error (display error).
2) Need to check after every merge (say f1 + f2, f1 + f2 + f3) that whether limit of 1 GB has been reached or not.

I am new to shell scripting, so I would appreciate the help.

Also, I need to write code for both UNIX & LINUX. What would be the difference in the code?
# 2  
Old 12-16-2011
Welcome to the forum.
you can try something like...

Code:
newsize=$(wc -c < merged_file)

if [ "$newsize" -gt 1073741824 ] ; then
 echo error
fi
# 1073741824 is the byte count for 1 GB

# 3  
Old 12-16-2011
For this, I would use split:
Code:
cat f1 f2 f3 ... | split -b 1GB - merged.

This will merge you files and generate 1GB files named merged.aa, merged.ab, merged.ac, etc. Each merged.xx file, except for the last, will be 1GB in size.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to Read the given file contents into a merged one file

Like to have shell script to Read the given file contents into a merged one file with header of path+file name followed by file contents into a single output file. While reading and merging the file contents into a single file, Like to keep the format of the source file. ... (4 Replies)
Discussion started by: Siva SQL
4 Replies

2. Shell Programming and Scripting

Script for getting the file merged

Hi, I have two files separated by bars at each line File 1 : A|4356|13456|23456 A|4356|2986|98732 A|8765|218|1432567 File 2: B|12|13456|1234567 B|11|13456|123456789 B|33|2986|98732 B|11|2986|14578965 B|8765|218|147584 Common field is third field like 13456, 2986 and 218 in both... (5 Replies)
Discussion started by: Mannu2525
5 Replies

3. UNIX for Dummies Questions & Answers

Restricting File List while doing ls

Is there any best way to restrict some of the listed files when you do ls. In the output i am doing grep -v wanted to see if i can use a better command to get this output. Command: > ls -lrt wf_Load_25.log.INSTANCE_21_20072.* -rw-r--r-- 1 infrmtca infrmtca 19373 Mar 12 14:14... (1 Reply)
Discussion started by: Ariean
1 Replies

4. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

5. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

6. Shell Programming and Scripting

The scripts not able to make the file to size 0, every times it go back to its original size

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (0 Replies)
Discussion started by: mridul10_crj
0 Replies

7. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

8. Shell Programming and Scripting

find with file size and show the size

Hi All... is the below command be modified in sucha way that i can get the file size along with the name and path of the file the below command only gives me the file location which are more than 100000k...but I want the exact size of the file also.. find / -name "*.*" -size +100000k ... (3 Replies)
Discussion started by: rpraharaj84
3 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. Shell Programming and Scripting

Sending output to a file - Merged from duplicate thread

Hi All, read dif echo `date +%Y%m%d`|./add $dif|./fmtdt %mon%dd The above script is for adding days to current date to find the new date. This script divides the current date into 20060220(YYYYMMDD) format and pass this output to add script. The add script will add the days to the... (2 Replies)
Discussion started by: muthu_nix
2 Replies
Login or Register to Ask a Question