Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

shell script problem

Posted on 1998-06-16
2
263 Views
Last Modified: 2010-04-21
Hello,
Can someone give me a C shell script example to do following:
It can append all the files under given directory(this directory name is given as an augument) and sub-directories to a newly generated file recursively.

Thanks
0
Comment
Question by:tian
2 Comments
 

Author Comment

by:tian
ID: 2008076
Edited text of question
0
 
LVL 2

Accepted Solution

by:
blowfish earned 100 total points
ID: 2008077
This should work.  It uses the find command to recurse through the directory and find
all "regular" files.  They are then concatenated using the cat command.  If the output
already exists, this script just keeps adding to the end, keep that in mind when you
run it.  

It requires two arguments, the first one is the path to the files to be read, the second is the path to the output file.  Don't write the output file into the same directory that you are reading input from.  

Hope this helps.  

#!/bin/csh

#  The first argument is the path to the files to be read
#  The second argument is the path to output file to be written

#  Since the find is recursive, the output should not go into the same
#  directory tree as the input

foreach X ( `find $1 -type f -print` )
  echo "Processing $X"
  cat $X >> $2
end

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question