i am passing below inputfils using while loop and ouput should be trim as below
INPUT:
src_SPS_d_Comment_Tran_File_20130417_001.dat
src_SPS_d_Corp_Adv_Tran_File_20130417_001.dat
src_SPS_d_Letter_Tran_File_20130417_001.dat
src_SPS_d_Loan_Level_File_20130417_001.dat
src_SPS_d_Payment_Tran_File_20130417_001.dat
OUTPUT:
Call_Center.txt
Comment_Tran.txt
Corp_Adv.txt
Letter_Tran.txt
Loan_Level.txt
Payment_Tran.txt
please tell me the command to trim as above.
$ sed -e "s/src_SPS_d_//" -e "s/File_20130417_001.dat/.txt/" input
Comment_Tran_.txt
Corp_Adv_Tran_.txt
Letter_Tran_.txt
Loan_Level_.txt
Payment_Tran_.txt
PS: Use those code tags.
$ for i in $(cat tmp/tmp.dat) ; do echo $i becomes $(echo $i | sed 's/src_SPS_d_\([^0-9]\+\)_[0-9_]\+.dat/\1.txt/'); done
src_SPS_d_Comment_Tran_File_20130417_001.dat becomes Comment_Tran_File.txt
src_SPS_d_Corp_Adv_Tran_File_20130417_001.dat becomes Corp_Adv_Tran_File.txt
src_SPS_d_Letter_Tran_File_20130417_001.dat becomes Letter_Tran_File.txt
src_SPS_d_Loan_Level_File_20130417_001.dat becomes Loan_Level_File.txt
src_SPS_d_Payment_Tran_File_20130417_001.dat becomes Payment_Tran_File.txt
everyday file date will change which mention in end of filename,so in that scenario above command will not give exact result right?
src_SPS_d_Comment_Tran_File_20130417_001.dat
src_SPS_d_Corp_Adv_Tran_File_20130417_001.dat
src_SPS_d_Letter_Tran_File_20130417_001.dat
src_SPS_d_Loan_Level_File_20130417_001.dat
src_SPS_d_Payment_Tran_File_20130417_001.dat.
Irrespective of any date i should get output as below.
Call_Center.txt
Comment_Tran.txt
Corp_Adv.txt
Letter_Tran.txt
Loan_Level.txt
Payment_Tran.txt
All right, maybe this is what you need:
$ cat input
src_SPS_d_Comment_Tran_File_20120417_001.dat
src_SPS_d_Corp_Adv_Tran_File_20130517_001.dat
src_SPS_d_Letter_Tran_File_20130417_001.dat
src_SPS_d_Loan_Level_File_20130418_001.dat
src_SPS_d_Payment_Tran_File_20130417_002.dat
$ sed -e "s/src_SPS_d_//" -e "s/_File_.*/.txt/" input
Comment_Tran.txt
Corp_Adv_Tran.txt
Letter_Tran.txt
Loan_Level.txt
Payment_Tran.txt
When i run command sed -e "s/src_SPS_d_//" -e "s/_File_.*/.txt/" input
i got result as below.
Call_Center_Reporting_20130417_001.dat
Comment_Tran.txt
Corp_Adv_Tran.txt
Letter_Tran.txt
Loan_Level.txt
Payment_Tran.txt
Your input data never had any kind of Call_Center_Reporting_
string in it. Look over the input data, and send a correct version. Thanks
sorry i missed it,below is correct one.
src_SPS_d_Call_Center_Reporting_20130417_001.dat
src_SPS_d_Comment_Tran_File_20130417_001.dat
src_SPS_d_Corp_Adv_Tran_File_20130417_001.dat
src_SPS_d_Letter_Tran_File_20130417_001.dat
src_SPS_d_Loan_Level_File_20130417_001.dat
src_SPS_d_Payment_Tran_File_20130417_001.dat
---------- Post updated at 04:57 AM ---------- Previous update was at 04:47 AM ----------
sorry i missed it,below is correct one
src_SPS_d_Call_Center_Reporting_20130417_001.dat
src_SPS_d_Comment_Tran_File_20130417_001.dat
src_SPS_d_Corp_Adv_Tran_File_20130417_001.dat
src_SPS_d_Letter_Tran_File_20130417_001.dat
src_SPS_d_Loan_Level_File_20130417_001.dat
src_SPS_d_Payment_Tran_File_20130417_001.dat
$ cat input
src_SPS_d_Call_Center_Reporting_20130417_001.dat
src_SPS_d_Comment_Tran_File_20130417_001.dat
src_SPS_d_Corp_Adv_Tran_File_20130417_001.dat
src_SPS_d_Letter_Tran_File_20130417_001.dat
src_SPS_d_Loan_Level_File_20130417_001.dat
src_SPS_d_Payment_Tran_File_20130417_001.dat
$ sed -e "s/src_SPS_d_//" -e "s/_File_[0-9_]*.dat/.txt/" -e "s/_Reporting_[0-9_]*.dat/.txt/" input
Call_Center.txt
Comment_Tran.txt
Corp_Adv_Tran.txt
Letter_Tran.txt
Loan_Level.txt
Payment_Tran.txt
Or, using a separate script file:
$ cat script
s/src_SPS_d_//
s/_File_[0-9_]*.dat/.txt/
s/_Reporting_[0-9_]*.dat/.txt/
$ sed -f script input
Call_Center.txt
Comment_Tran.txt
Corp_Adv_Tran.txt
Letter_Tran.txt
Loan_Level.txt
Payment_Tran.txt