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?

Welcome to the forum.
you can try something like...

newsize=$(wc -c < merged_file)

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

For this, I would use man split (linux):

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.