File Concatenation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File Concatenation
# 1  
Old 11-15-2006
File Concatenation

Hi,

I want to write a generic shell script, which can concatenate n number of files passed as parameter ;to an output file which is again a parameter

Example
catfl.sh outfl.txt a.txt b.txt c.txt (3 files to be concatenated into a file outfl.txt)
catfl.sh outfl.txt a.txt b.txt(2 files to be concatenated into a file outfl.txt)

The directories in which the input files are stored would contain a number of other text files.

I am fairly new to unix . Any help as to how to acheive the above results is greatly appreciated.

Thanks much in advance!

Sam
# 2  
Old 11-15-2006
Hi The most simplest script would be....

you would be able to supply full path names on the command line
If the files always live in the same place then you can code the path names in the script.....
Note: There is NO checking to ensure that the first file is the outputfile that you require and that the txt files actually exist and are readable.....


#!/bin/sh
if [ $# -ge 2 ] # Need to check to make sure we have 2 files as a min
then
outfile=$1
shift;
files=$*
cat $files > $outfile
else
echo "Usage: `basename $0` [output file] [textfile listing]"
fi
# 3  
Old 11-15-2006
Great.

Thanks a lot
# 4  
Old 11-21-2006
I think this will be more robust.......u can test this script for as many files as u want.....

#!/bin/sh
#script to cat number of files given as an argument
if [ $# -eq 0 ]
then
echo " Enter the files which are to be catted as argument "
fi
if [ $# -eq 1 ]
then
echo " usage :: $0 <outputfile> <inputfile1> <inputfile2> ......."
fi
count=`expr $# - 1`
echo $count
echo $*
#shift jam1 > jam2
#cat jam2
#i=2
catfile=$1
while [ $# -gt 1 ]
do
echo $*
cat $2 $3 > jam
shift 2
done
cat jam > catfile

txs,
jam
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Concatenation of multiple files based on file pattern

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

2. Shell Programming and Scripting

Issue in Concatenation/Joining of lines in a dynamically generated file

Hi, I have a file containing many records delimited by pipe (|). Each record should contain 17 columnns/fields. there are some fields having fields less than 17.So i am extracting those records to a file using the below command awk 'BEGIN {FS="|"} NF !=17 {print}' feedfile.txt... (8 Replies)
Discussion started by: TomG
8 Replies

3. Shell Programming and Scripting

File concatenation

awk '{$2=$2":"$8"-"$3;$3=$NF;$4=$NF="";print $0 | $10=$10":"$8"-"$18;$11=$NF;$12=$NF="";print $0 }' design.txt Trying to concatenate specific fields in a spreadsheet and the others remain unchanged. I attached an excel spreadsheet (all the data comes from a design.txt), but I put an example... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

File Concatenation in a format

I have some files named as: error_abc.txt error_def.txt error_ghi.txt I want to concatenate all these into a single file say error_all.txt. The error_all.txt should be displayed like: ... (11 Replies)
Discussion started by: ankur328
11 Replies

5. Shell Programming and Scripting

Help with String concatenation

I have a script which is migrated from AIX to Linux & now while running it is no able to concatenate string values The string concatenation step under while loop is not displaying desired result Please find below the piece of code: while read EXT_FILE ; do EXT_FILE=$EXT_FILE.ext.sent echo... (7 Replies)
Discussion started by: PreetArul
7 Replies

6. Shell Programming and Scripting

Erroneous file concatenation.

I have more than one files in a directory , namely GLOW_OUT.txt FIELD_OUT.txt BASE_OUT.txt ... SHOW_OUT.txt What I wanted to do is to I am working in Korn Shell What I did was : for file in <directory_name>/*.* ;do cat $file | grep -v '^$' >> temp_file rm $file done ... (7 Replies)
Discussion started by: kumarjt
7 Replies

7. Shell Programming and Scripting

String concatenation

Hi, I have two files. cat file.txt a b c d cat file1.txt j k l m I need the output as a:j (12 Replies)
Discussion started by: nareshkumar522
12 Replies

8. Shell Programming and Scripting

Concatenation

How can I do this: date = 4 -----------> 04 Month= 3-----------> 03 I wish to make a varibale named Var1 which will hold the value of current date and month value as: 2 digits for date. 2 digits for month. So finally var1 should hold value as 0403 --- MMDD (11 Replies)
Discussion started by: Asteroid
11 Replies

9. Shell Programming and Scripting

File concatenation problem

I have written a script to find particular text files created within the last 24 hours and concatenate them all into a single concat.txt file. The problem that I am running into is that the last line of the text files do not terminate with <CR><LF> characters (as do all the other lines in each... (3 Replies)
Discussion started by: jvander
3 Replies

10. Shell Programming and Scripting

Concatenation

What is syntax for String concatenation? I have $1 as directory. $var is some variable value '/' String value. How do I have to concatenate if I have to run utility - util $1 followed by '/' followed by $var There is no space between these three. (2 Replies)
Discussion started by: videsh77
2 Replies
Login or Register to Ask a Question