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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Concatenation Asteroid Shell Programming and Scripting 11 04-04-2007 06:15 AM
string concatenation systemsb UNIX for Dummies Questions & Answers 7 04-04-2006 12:03 PM
Implementing Concatenation(cat) toughguy2handle High Level Programming 2 09-22-2005 02:10 AM
File concatenation problem jvander Shell Programming and Scripting 3 07-18-2005 02:53 PM
Concatenation videsh77 Shell Programming and Scripting 2 12-14-2004 06:13 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 11-15-2006
samit_9999 samit_9999 is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 21
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 (permalink)  
Old 11-15-2006
Andrek Andrek is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 122
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 (permalink)  
Old 11-15-2006
samit_9999 samit_9999 is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 21
Great.

Thanks a lot
  #4 (permalink)  
Old 11-21-2006
jam_prasanna jam_prasanna is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 21
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
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 10:57 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