LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2010, 10:19 AM   #1
new_user28
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Rep: Reputation: 0
Question 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
 
Old 08-05-2010, 10:33 AM   #2
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
how about just typing "find /path/to/directory >files.txt"?
 
Old 08-05-2010, 10:39 AM   #3
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by new_user28 View Post
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.
 
Old 08-05-2010, 11:13 AM   #4
new_user28
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi,
I do not have the script yet, I need to create a new one from scratch. So need help regarding this.
 
Old 08-05-2010, 11:20 AM   #5
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Ok, do you want a list of the files or of their contents? You just got suggestions for both...
 
Old 08-05-2010, 11:27 AM   #6
new_user28
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Original Poster
Rep: Reputation: 0
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..
 
Old 08-05-2010, 12:21 PM   #7
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by new_user28 View Post
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.
 
Old 08-05-2010, 12:30 PM   #8
vigilandy
Member
 
Registered: Mar 2010
Location: Tokyo
Distribution: Arch, Fedora
Posts: 71

Rep: Reputation: 23
All these answers to your homework question. This may help: How to Create a First Shell Script
 
1 members found this post helpful.
Old 08-05-2010, 05:29 PM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

Last edited by theNbomr; 08-05-2010 at 05:34 PM.
 
Old 08-06-2010, 04:30 AM   #10
tommyttt
Member
 
Registered: Oct 2009
Location: Federal Way, WA
Distribution: openSUSE 11.4 x86_64, openSuSE 12.1, Fedora 15
Posts: 207

Rep: Reputation: 34
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
 
Old 08-06-2010, 08:36 AM   #11
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
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.
 
Old 08-06-2010, 11:10 AM   #12
pete83
Member
 
Registered: Dec 2007
Location: The Netherlands
Distribution: Ubuntu
Posts: 50

Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shell and perl scripts deelinux Linux - Newbie 6 03-23-2010 03:55 PM
crypt() perl function to encrypt Password in shell scripts or How Encrypt passwords ? balakrishnay Linux - General 13 01-14-2010 10:35 AM
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 07:24 AM
shell and perl scripts srnerkar1 Programming 2 12-03-2005 04:07 PM
perl scripts mimf Linux - Newbie 3 12-02-2003 12:10 AM


All times are GMT -5. The time now is 08:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration