Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shell script to change files name

Posted on 2006-05-25
6
Medium Priority
?
344 Views
Last Modified: 2010-04-21
Hi experts,
I have 500 files with names cctrk_01.sql....cctrk_500.sql. The format of the files content are the same as the one below.


-- Program:   dmp_inbc_s.ppc
-- Function:  dmp_dl_inbc_by_pk
-- Statement: 1 of 1 within function

prompt generating explain plan for statment #10
explain plan set statement_id='cctrk_10' for
DELETE FROM INCOL_BATCH_CONTROL
WHERE SERVE_SID = :sql_serve_sid AND HOME_SID = :sql_home_sid AND SEQUENCE_NO = :sql_sequence_no ;

spool cctrk_10.txt
select plan_table_output
from   table(dbms_xplan.display('PLAN_TABLE',
          'cctrk_10', 'ALL'));
spool off

prompt end of explain plan for statment #10



I want to write a shell script to change the names of the files to a combination of the program and function. For example, cctrk_10.sql will be cctrk_dmp_inbc_s.ppc_dmp_dl_inbc_by_pk, and every occurance of #number, cctrk_number, cctrk_number.txt should also be a combination of the program and function. For example, #10 will be #dmp_inbc_s.ppc_dmp_dl_inbc_by_pk,
cctrk_10 will be cctrk_dmp_inbc_s.ppc_dmp_dl_inbc_by_pk, and cctrk_10.txt will also be cctrk_dmp_inbc_s.ppc_dmp_dl_inbc_by_pk.txt.

Any help will be greatly appreciated.




0
Comment
Question by:jkopoku
  • 3
  • 3
6 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 16763145
perl -i -pe '$x{$1}=$2 if /-- (Program|Function):\s*(\S+)/; if( eof ){ $r="cctrk_$x{Program}_$x{Function}"; rename $ARGV,$r or warn "$ARGV $r $!"}' cctrk_*.sql
0
 

Author Comment

by:jkopoku
ID: 16763558
Thanks for helping me. Your script changes the files name alright, but the content does not change.
0
 
LVL 85

Expert Comment

by:ozo
ID: 16763613
What do you want to change in the content?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:jkopoku
ID: 16763679

cctrk_10.txt to cctrk_program_function.txt
cctrk_10 to cctrk_program_function
 #10 to # program_function

This number is based on the name of the file, therefore, it will be different in other files. It is 10 because the name of the file is cctrk_10.sql


0
 

Author Comment

by:jkopoku
ID: 16765184
Maybe I am not very clear. I want all change all occurance of cctrk_10.txt to cctrk_the new file name.txt. So in this case cctrk_10.txt will change to cctrk_dmp_inbc_s.ppc_dmp_dl_inbc_by_pk.txt,  cctrk_10 will change to  cctrk_dmp_inbc_s.ppc_dmp_dl_inbc_by_pk, and #10 will become #dmp_inbc_s.ppc_dmp_dl_inbc_by_pk

Thanks.



0
 
LVL 85

Accepted Solution

by:
ozo earned 1600 total points
ID: 16767023
perl -i -pe '$x{$1}=$2 if /-- (Program|Function):\s*(\S+)/; $x="$x{Program}_$x{Function}"; ($n)=$ARGV=~/(\d+)/; s/(#|cctrk_)$n/$1$x/g; if( eof ){ $r="cctrk_$x"; rename $ARGV,$r or warn "$ARGV $r $!"}' cctrk_*.sql
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question