The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to merge these two files? fedora Shell Programming and Scripting 3 02-12-2008 06:45 PM
merge files koti_rama Shell Programming and Scripting 5 12-24-2007 10:59 PM
use of sed over cat to merge files miwinter UNIX for Advanced & Expert Users 2 11-28-2007 01:36 PM
help in merge files u263066 Shell Programming and Scripting 5 07-24-2006 03:24 AM
Using NAWK to merge two files madhunk Shell Programming and Scripting 7 06-07-2006 10:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-06-2007
lestat_ecuador lestat_ecuador is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 28
Exclamation How to merge files

Hello guys,

I gotta question, i have a lot of log files (simple text) and i need to merge them in group of 10 files, one next to the other, that have sense?

For example, i have the files:

File1
File2
File3
File4
.
.
File100

I need to merge the contents of each file into a new file named Total1, but into Total1 only will be the File1 to File10, then will be another Total2 with the content of File11 to File20... etc, etc... Please your help.

Thanx
  #2 (permalink)  
Old 06-06-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Lestat,
See if this works for you:
Code:
typeset -i mCnt=0
typeset -i mSeq=1
mOutFile='Total1'
for mFName in `find . -type f`
do
  cat mFName >> $mOutFile
  mCnt=$mCnt+1
  if [ ${mCnt} -eq 10 ]; then
    mSeq=$mSeq+1
    mOutFile='Total'$mSeq
    mCnt=0
  fi
done
  #3 (permalink)  
Old 06-06-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
Another solution (ksh or bash) :
Code:
# Script file: concat.sh

shopt -s extglob # Not need for ksh

src_prefix=File
out_prefix=Total

typeset -i src_seq out_seq

for src_file in ${src_prefix}+([0-9])
do
   src_seq=${src_file#${src_prefix}}
   (( out_seq=src_seq/10+1 ))
   echo "cat ${src_file} >> ${out_prefix}${out_seq}"
done
Execution:
Code:
$ ls File*
File1  File100  File11  File19  File2  File9  File91  File92  File99
$ concat.sh
cat File1 >> Total1
cat File100 >> Total11
cat File11 >> Total2
cat File19 >> Total2
cat File2 >> Total1
cat File9 >> Total1
cat File91 >> Total10
cat File92 >> Total10
cat File99 >> Total10$
Jean-Pierre.
  #4 (permalink)  
Old 06-07-2007
venkata.ganesh venkata.ganesh is offline
Registered User
  
 

Join Date: May 2007
Location: bangalore
Posts: 6
merge number of files

code
#!/bin/sh
echo enter file name
read f
echo enter number of such files
read n
i=1
while test $i -ne $n
do
echo $f$i >> outfile
cat $f$i >> outfile
i=`expr $i + 1`
done



by the use of above code you can see the file name also before its content.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0