Reading Table name from a list of files in a Directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading Table name from a list of files in a Directory
# 1  
Old 01-17-2012
Reading Table name from a list of files in a Directory

Hi ,

I have searched through the forum but not able to find out any help Smilie

i have a directory having lot of files which contains sql statemtns

eg : file 1 contains
Code:
select from table_name1 where .....................

select from 
table_name2 where ..........

select 
from 
table_name3 where ..........


select
from 
table_name4
where ..........................

I need to get table_name1 - table_name4 from this file .
how to write the script . please help Smilie

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 01-17-2012 at 05:27 AM..
# 2  
Old 01-17-2012
Hi,
Please use this code

$ sed -n '/from/,/where/p' f1.txtawk '{print $4}'
O/p:- 
---- 
$ sed -n '/from/,/where/p' f1.txtawk '{print $4}'
xyz 
abc 
$ cat f1.txt 
select * from xyz where 
select * from abc where 

in your case read one by one file and run the above command on each line

thanks,
venkat
This User Gave Thanks to venkatareddy For This Post:
# 3  
Old 01-17-2012
Code:
$ tr "\n" " " < input.txt | nawk '{for(i=1;i<=NF-1;i++){if($i~/from/){print $(i+1)}}}'
table_name1
table_name2
table_name3
table_name4

This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 01-18-2012
thanks mightss .. Smilie

---------- Post updated at 04:12 PM ---------- Previous update was at 03:46 PM ----------

one doubt if i have 5 files in the folder instead of 1 how will i manage

---------- Post updated at 04:38 PM ---------- Previous update was at 04:12 PM ----------

also is there any way to write the script not using awk or sed
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

2. Shell Programming and Scripting

Reading contents of files from a directory

I have a directory with the files, 1st: I want to Diplay each filename, underline it 2nd: Display the contents under the filename and 3rd: Redirect the above content to other file 4th: Remove the files from the directory #!/bin/ksh for i in $( cat $a/b/c.txt ) do echo "... (1 Reply)
Discussion started by: Aditya_001
1 Replies

3. Shell Programming and Scripting

reading information from a table and apply a command on multiple files

Hey gyuz, I wanna calculate the number of mapped reads of a bam file in a region of interest. I used this code to do so : samtools view input.bam chrname:region1 > region1.txt This will store all the reads from given bam file within the region of interest in region1.txt Now I have... (5 Replies)
Discussion started by: @man
5 Replies

4. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

5. Shell Programming and Scripting

Reading in all files from parent directory (GAWK)

Hi all, I'm very, very new to scripting (let alone SHELL) and was wondering if anyone could help me out as I seem to be in a spot of bother. I collect data (.dat files) which are automatically seperated into several sub directories, so the file paths I'm reading in at the moment would be... (11 Replies)
Discussion started by: gd9629
11 Replies

6. Shell Programming and Scripting

reading files from a directory.

Can some body help me to code this? go to a specific directory.(/home/abcd/test) file1.txt, file2.txt, ... .. filen.txt read the files in side the folder 'test' and print the content of each file into other folder in the same directory lets say(testresult) with the same file name... (4 Replies)
Discussion started by: rocking77
4 Replies

7. UNIX for Dummies Questions & Answers

Reading files in script from another directory

Hi I'm trying to call my files from different directories in my script. Can you please help me. Here is my script: #!/bin/bash #---------------------------------------------------------------------------------------------------------------------- #This script allows the user... (1 Reply)
Discussion started by: ladyAnne
1 Replies

8. AIX

reading files from a directory.

Hi all, I have a shell script where it processes a set of files from a particular directory (shared location among 4 servers). i.e. under this directory /shared/work/ I have a set of files that needs to be processed. Since the number of files are alot, I have this script to be run from 4... (2 Replies)
Discussion started by: haroon_a
2 Replies

9. Shell Programming and Scripting

How to Pull out multiple files from DB table and redirect all those files to a differetn directory?

Hi everyone!! I have a database table, which has file_name as one of its fields. Example: File_ID File_Name Directory Size 0001 UNO_1232 /apps/opt 234 0002 UNO_1234 /apps/opt 788 0003 UNO_1235 /apps/opt 897 0004 UNO_1236 /apps/opt 568 I have to... (3 Replies)
Discussion started by: ss3944
3 Replies

10. Shell Programming and Scripting

Reading files in directory

Hi Everyone , have a nice day i need a help on this thing algo is something like in certain path like /root/user1 i have many files , i need a code which could open every file one by one and then each file has contents like this <moid>CcnCounters=CAPv3-Received-Total-Requests, Source =... (3 Replies)
Discussion started by: Dastard
3 Replies
Login or Register to Ask a Question