How to process select list of files and output to the same file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to process select list of files and output to the same file?
# 1  
Old 02-23-2013
How to process select list of files and output to the same file?

Hi,

I've a list of files

ac_info.tps, subscription_array.tps, .......and many other files

one of the file, bin_range_list.tps has the following content

Code:
CREATE OR REPLACE TYPE "BIN_RANGE_LIST"                                          AS TABLE OF BIN_RANGE_ELEM;
/
grant execute on BIN_RANGE_LIST to SUPERB_TXN;

how do I extract the portion on grant.and place result in a file called bin_range_list_to_superb_txn?
Code:
grant execute on BIN_RANGE_LIST to SUPERB_TXN;

understand that for one file we can do the following:

Code:
cat bin_range_list | grep "grant" > bin_range_list_to_superb_txn

but how do I repeat the above process for a list of files?

thanks
# 2  
Old 02-23-2013
If you have grep supporting the -h option:
Code:
grep -h grant *.tps > bin_range_list_to_superb_txn

Or with awk:
Code:
awk 'index($0,"grant")' *.tps > bin_range_list_to_superb_txn

# 3  
Old 02-23-2013
Hi elixir sinari,

I have a list of files and the output for each file is different,

bc_attribute_rec.tps,
bc_attribute_update.tps
bc_attribute_update_arr.tps

output of the files

bc_attribute_rec_to_txn.tps,
bc_attribute_update_to_txn.tps
bc_attribute_update_arr_to_txn.tps

so how do I achieve it?

thanks
# 4  
Old 02-23-2013
Run this in the directory having ONLY the input .tps files:
Code:
for i in *.tps
do
 grep grant "$i" > "${i%.*}_to_txn.tps"
done

# 5  
Old 02-24-2013
Are we dealing with moving targets or sloppy wording? In post#1, the output file should be bin_range_list_to_superb_txn, in post#3 it was sth_to_txn.tps, sth being the input file name with its suffix deleted.
Guessing that the file name addendum should be the user name granted to, I'd propose
Code:
$ awk '/grant/ {fn=FILENAME"_"$(NF-1)"_"$NF; gsub(/\.tps|;/,"",fn); print > fn}' *.tps

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting - Select multiple files from numbered list

I am trying to have the user select two files from a numbered list which will eventually be turned into a variable then combined. This is probably something simple and stupid that I am doing. clear echo "Please Select the Show interface status file" select FILE1 in *; echo "Please Select the... (3 Replies)
Discussion started by: dis0wned
3 Replies

2. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

3. Shell Programming and Scripting

How to list files names and sizes in a directory and output result to the file?

Hi , I'm trying to list the files and output is written to a file. But when I execute the command , the output file is being listed. How to exclude it ? /tmp file1.txt file2.txt ls -ltr |grep -v '-' | awk print {$9, $5} > output.txt cat output.txt file1.txt file2.txt output.txt (8 Replies)
Discussion started by: etldeveloper
8 Replies

4. UNIX for Dummies Questions & Answers

Select distinct sequences from fasta file and list

Hi How can I extract sequences from a fasta file with respect a certain criteria? The beginning of my file (containing in total more than 1000 sequences) looks like this: >H8V34IS02I59VP SDACNDLTIALLQIAREVRVCNPTFSFRWHPQVKDEVMRECFDCIRQGLG YPSMRNDPILIANCMNWHGHPLEEARQWVHQACMSPCPSTKHGFQPFRMA... (6 Replies)
Discussion started by: Marion MPI
6 Replies

5. Shell Programming and Scripting

Select only the lines of a file starting with a field which is matcing a list. awk?

Hello I have a large file1 which has many events like "2014010420" and following lines under each event that start with text . It has this form: 2014010420 num --- --- num .... NTE num num --- num... EFA num num --- num ... LASW num num --- num... (9 Replies)
Discussion started by: phaethon
9 Replies

6. UNIX for Dummies Questions & Answers

Select text between current date and output to new txt file

Hi guys, brand new to this thread and very very new to UNIX...so go easy please! Anyway I have a file that looks like this: >>-------------------------------------------------------------------------- Date/Time/Eng. : 2012-06-22 / 00:26 / DS Reported problem : (SD) ... (5 Replies)
Discussion started by: martin0852
5 Replies

7. UNIX Desktop Questions & Answers

Script to select a file from a list

i m trying to write a script that will print all the txt files at /home/ directory and will allow a selection of a file and then print the file name. this is what i wrote so far: echo "please select the file from the list " list=$(ls -f *.txt /home/) array=( ) for machine in $list doat... (1 Reply)
Discussion started by: boaz733
1 Replies

8. Shell Programming and Scripting

Running a select script through UNIX and sending output to file

Hi, (Oracle, AIX) I have googled this and searched this forum, however I haven't had much luck with an answer and have tried several different things. Basically I have a SQL select statement which generates a whole load of UPDATE statements, I want to run the select statement via... (13 Replies)
Discussion started by: dbchud
13 Replies

9. Shell Programming and Scripting

select data from oracle table and save the output as csv file

Hi I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string,... (2 Replies)
Discussion started by: rdhanek
2 Replies

10. Shell Programming and Scripting

I need a script to find socials in files and output a list of those files

I am trying to find socail security numbers in files in (and under) a specific directory and output a list of the files where they are found... the format would be with no dashes just 9 numeric characters in a row. I have tried this: find /DirToLookIn -exec grep '\{9\}' /dev/null {} \; >>... (1 Reply)
Discussion started by: NewSolarisAdmin
1 Replies
Login or Register to Ask a Question