LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell or Perl Scripts (https://www.linuxquestions.org/questions/linux-newbie-8/shell-or-perl-scripts-824370/)

new_user28 08-05-2010 09:19 AM

Shell or Perl Scripts
 
Hi,
I am to new to scripting and I have a urgent requirement that I should do. The requirement is.

A shell script that reads a directory and its sub directories and generate a flat file or csv file at the end so that I can use that file to load data into my tables.

Please very urgent.

Thanks in Advance

zirias 08-05-2010 09:33 AM

how about just typing "find /path/to/directory >files.txt"?

jstephens84 08-05-2010 09:39 AM

Quote:

Originally Posted by new_user28 (Post 4056836)
Hi,
I am to new to scripting and I have a urgent requirement that I should do. The requirement is.

A shell script that reads a directory and its sub directories and generate a flat file or csv file at the end so that I can use that file to load data into my tables.

Please very urgent.

Thanks in Advance

What part of your script are you having problems with? for the most part you could do something like

find $1 -print >> filestruct.csv

The $1 would allow you to give a top level directory. Now you will need to refine that a bit to remove the filenames that come up.

new_user28 08-05-2010 10:13 AM

Hi,
I do not have the script yet, I need to create a new one from scratch. So need help regarding this.

zirias 08-05-2010 10:20 AM

Ok, do you want a list of the files or of their contents? You just got suggestions for both...

new_user28 08-05-2010 10:27 AM

Hi,
I just need to read the info from the file like the file names, no.of files in that directory type of files in that directory..

jstephens84 08-05-2010 11:21 AM

Quote:

Originally Posted by new_user28 (Post 4056916)
Hi,
I just need to read the info from the file like the file names, no.of files in that directory type of files in that directory..

I am a little confused on what you are actually looking for. However
if you are wanting to find just the directory structure you could do the following

Code:

find . -type d > myTree.csv
this would get all directories only from the current working directory. If you are placing this in a batch script replace . with $1 so you can specify a directory from outside the directory.

for getting a list of all files then you could do the following

Code:

find . -type f > myTreeFile.csv
again change as needed.

vigilandy 08-05-2010 11:30 AM

All these answers to your homework question. This may help: How to Create a First Shell Script

theNbomr 08-05-2010 04:29 PM

Quote:

shell script that reads a directory and its sub directories and generate a flat file or csv file at the end
It is easy to generate a flat file or CSV file. Doing so with the desired contents will require more information. What information is to go into the file? By your description of the problem, the following bash script satisfies the requirements:
Code:

#! /bin/bash
find $1
echo foobar > flatfile.csv

When describing a problem, do not forget that the reader knows absolutely nothing about the problem domain, beyond what you provide. Be complete and concise.
--- rod.

tommyttt 08-06-2010 03:30 AM

NewUser_28:

We are not here to do your homework for you. If you want to work in the computer field, you need to do the work yourself. That means spending time researching, reading, trying different things and making lots of mistakes from which you learn. That is what we have done. We volunteer our time on forums to help newbiew and each other.

Don't just come here and ask us to do your assignments. Think about something, your instructor most likely reads these forums also and likely will be wise to your methods.

Tom

MTK358 08-06-2010 07:36 AM

You also never explained what the problem really is!

If you at least want a chance of us helping, you must post the exact specs of the output file to the last detail, because we can't read your mind.

pete83 08-06-2010 10:10 AM

Sorry but i'm giving him a script.

Code:

#!/bin/bash

DIR=/dir/subdir

ls -alR ${DIR} > flatfile.txt

The -R option with the ls command shows subdirs recursive.


All times are GMT -5. The time now is 11:39 AM.