Reading a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a file
# 1  
Old 05-12-2009
Reading a file

I have all the subdirectories names in a text file. I have to read that text file and move that subdirectory and come back to orginal directory and again read anoteh sub directory like that.
main > sub1 > testsub1.txt
> sub2 > testsub2.txt
> sub3 > testsub3.txt
> sub4 > testsub4.txt
I have done all the subdirectories names in free.txt which contains:
Code:
sub1
sub2
sub3

like entries.

Here i need a shell script to read free.txt file, and go to sub1 directory and read testsub1.txt file and come back to sub2 and read testsub2.txt like that .i am using the below script but i am not getting properly. Can anyone suggest me.
Code:
cat test.txt | while read LINE
do
CD1=`ls ${LINE}/inbox`
done


Last edited by Yogesh Sawant; 05-12-2009 at 05:27 AM.. Reason: added code tags
# 2  
Old 05-12-2009
Hi Kiran,
Would u pl elaborate on your problem?
May I know your goal of reading testsub1.txt file.
u can try the following also:
#!/usr/bin/tcsh

set mylist = `cat test.txt`
foreach mydir ($mylist)
cd $mydir
cat *.txt
cd -
end
and save this script out of the directory that contains all these sub1, sub2, sub3 etc.,
and source it in the directory with sub1, sub2, sub3 there as
source ../myscript

Thanks,
Sowmya
# 3  
Old 05-12-2009
reading directories from the file and iterate it and retrieve the file

Thanx for Reply Soumya.
The thing i need shel script in unix. The problem is..

I have "main" directory.under that "sub1,sub2,sub3" like n directories are there. each subdirectory is having "inbox" subdirectory. I have to iterate all the directories and get the file in "inbox" directory of each sub directory. Please do the needful
# 4  
Old 05-12-2009
Hi Kiran,
Thanks for the elaboration.
Still I could not get the output of reading the file in the inbox.
Anyway, pl try this shell script:
#!/usr/bin/tcsh
set mylist = `cat free.txt`
foreach mydir ($mylist)
cat $mydir/inbox/*.txt
end

Thanks,
Sowmya
# 5  
Old 05-12-2009
reading directories from the file and iterate it and retrieve the file

foreach in not working Soumya
# 6  
Old 05-12-2009
Hello kiran ,
what you have written is correct.

I have also tried the same it works fine

cat test.txt | while read LINE
do
CD1=`ls ${LINE}/inbox`
echo $CD1 ### this is a extar which i have included for checking.
done


and text.txt file contains

sub1
sub2
sub3

in which I have created files under each folder.

check this out if any problem you can get back.
# 7  
Old 05-12-2009
reading directories from the file and iterate it and retrieve the file

Praveen,
Only sub1 is iterating and remaining is sub directories are not iterating. Can u suggest
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

5. Shell Programming and Scripting

fatal: cannot open file `TNAME' for reading (No such file or directory)

Hi, I am running this command through a shell script and getting the error mentioned in the subject line: testing.awk -f x.txt TNAME My testing.awk file contains something like ++++++++++++++++++ #!/usr/bin/awk -f BEGIN{ TAB_NAME="INSERT_ONE_" ARGV ; } if ( $1=="JAM_ONE" &&... (1 Reply)
Discussion started by: kunwar
1 Replies

6. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

7. UNIX for Dummies Questions & Answers

Reading from a file(passing the file as input parameter)

hi I have a shell script say primary.sh . There is a file called params my scenario is primary.sh should read all the values and echo it for example i should pass like $primary.sh params output would be Abc ... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

8. UNIX for Advanced & Expert Users

Reading a file and sending mail based on content of the file

Hi Gurus, I am having an requirement. i have to read a list file which contains file names and send mail to different users based on the files in the list file. eg. if file a.txt exists then send a mail to a@a.com simillary for b.txt,c.txt etc. Thanks for your help, Nimu (6 Replies)
Discussion started by: nimu1979
6 Replies

9. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question