![]() |
Hello and Welcome from 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 |
| 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 07:15 AM |
| string concatenation | systemsb | UNIX for Dummies Questions & Answers | 7 | 04-04-2006 01:03 PM |
| Implementing Concatenation(cat) | toughguy2handle | High Level Programming | 2 | 09-22-2005 03:10 AM |
| File concatenation problem | jvander | Shell Programming and Scripting | 3 | 07-18-2005 03:53 PM |
| Concatenation | videsh77 | Shell Programming and Scripting | 2 | 12-14-2004 06:13 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|