The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
concatenate files sorted by date docaia Shell Programming and Scripting 2 08-15-2008 11:23 PM
How to concatenate 2 files using awk? pdtak Shell Programming and Scripting 2 03-12-2008 09:12 AM
Concatenate text of two files in UNIX. Uniq UNIX for Advanced & Expert Users 1 01-19-2007 03:53 AM
How to concatenate all files. s80bob UNIX for Dummies Questions & Answers 1 08-22-2005 01:20 PM
Split n then concatenate files. praveen.pinto UNIX for Advanced & Expert Users 4 02-15-2005 08:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-02-2008
Registered User
 

Join Date: Jan 2008
Posts: 15
Stumble this Post!
Script to concatenate several files

I need a script to concatenate several files in one step, I have 3 header files say file.S, file.X and file.R, I need to concatenate these 3 header files to data files, say file1.S, file1.R, file1.X so that the header file "file.S" will be concatenated to all data files with .S extentions and so on for "file.X" and file.R with the .X and .R data files..
I tried using wild cards, like:

cat file.S file[1-50].S > file[1-50].SP

but I got a message saying that file[1-50].SP does not match
so can this be done through a script? this will save a LOT of time for me, so if someone can help me it will be much appreciated
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-02-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,953
Stumble this Post!
If I understand your question this should work (not tested!):

Code:
for letter in S R X
do
  for i in file[0-9].$letter
  do
    cat file.$letter > "$i"P
    cat "$i" >> "$i"P
  done
done
Regards
Reply With Quote
  #3 (permalink)  
Old 02-03-2008
Registered User
 

Join Date: Jan 2008
Posts: 15
Stumble this Post!
thank you,
can you please explain to me each line?
for letter X R S
is a loop, that begins with X, then R then S, so letter is a variable, it can be substituted by i or x right?
then what does the line before done do?
Reply With Quote
  #4 (permalink)  
Old 02-03-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,953
Stumble this Post!
These are basic shell loops, you should read some books or tutorials about scripting. To learn scripting is to read about it and try to find things out yourself.
Echo the variables within the loop like:

Code:
for letter in S R X
do
  for i in file[0-9].$letter
  do
    echo file
    echo $letter
    echo file.$letter
    echo "$i"P
    echo "$i"
  done
done
Change the names of the variables and watch what happens and so forth.

Here you can read something about loops and variables (Googled on 'ksh scripting tutorial'):

KSH script BASICS


Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0