![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
|||||
|
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
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$ |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|