Use search pattern to reformat the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use search pattern to reformat the output
# 1  
Old 12-30-2013
Use search pattern to reformat the output

I have below file listing
Code:
] ls -1 *.txt
MISTradesReport_141105_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-24.txt
MISTradesReport_141106_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-24.txt
MISTradesReport_141107_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-24.txt
MISTradesReport_141108_d130240_VOLCKER_NA_BOND_FEED_2013-12-24.txt
MISTradesReport_141109_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-24.txt
MISTradesReport_141110_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-24.txt
MISTradesReport_141333_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-28.txt
MISTradesReport_141334_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-28.txt
MISTradesReport_141335_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-28.txt
MISTradesReport_141336_d130240_VOLCKER_NA_BOND_FEED_2013-12-28.txt
MISTradesReport_141337_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-28.txt
MISTradesReport_141338_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-28.txt
MISTradesReport_141362_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-29.txt
MISTradesReport_141363_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-29.txt
MISTradesReport_141364_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-29.txt
MISTradesReport_141365_d130240_VOLCKER_NA_BOND_FEED_2013-12-29.txt
MISTradesReport_141366_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-29.txt
MISTradesReport_141367_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-29.txt
MISTradesReport_141403_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt
MISTradesReport_141404_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt
MISTradesReport_141405_d130240_VOLCKER_NA_BOND_FEED_2013-12-30.txt
MISTradesReport_141406_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt
MISTradesReport_141407_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-30.txt
MISTradesReport_141408_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt
MISTradesReport_141409_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt
MISTradesReport_141410_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt
MISTradesReport_141411_d130240_VOLCKER_NA_BOND_FEED_2013-12-30.txt
MISTradesReport_141412_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt
MISTradesReport_141413_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-30.txt
MISTradesReport_141414_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt
MISTradesReport_141415_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt
MISTradesReport_141416_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt
MISTradesReport_141417_d130240_VOLCKER_NA_BOND_FEED_2013-12-30.txt
MISTradesReport_141418_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt
MISTradesReport_141419_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-30.txt
MISTradesReport_141420_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt

Need outout as
Code:
mv MISTradesReport_141105_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-24.txt  VOLCKER_EMEA_LOANIQ_FEED_2013-12-24.txt
mv MISTradesReport_141106_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-24.txt  VOLCKER_NA_LOANIQ_FEED_2013-12-24.txt
mv MISTradesReport_141107_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-24.txt VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-24.txt
mv MISTradesReport_141108_d130240_VOLCKER_NA_BOND_FEED_2013-12-24.txt  VOLCKER_NA_BOND_FEED_2013-12-24.txt
mv MISTradesReport_141109_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-24.txt  VOLCKER_NA_CDS_CRDI_FEED_2013-12-24.txt
mv MISTradesReport_141110_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-24.txt  VOLCKER_EMEA_BOND_FEED_2013-12-24.txt
mv MISTradesReport_141333_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-28.txt  VOLCKER_EMEA_LOANIQ_FEED_2013-12-28.txt
mv MISTradesReport_141334_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-28.txt  VOLCKER_NA_LOANIQ_FEED_2013-12-28.txt
mv MISTradesReport_141335_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-28.txt VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-28.txt
mv MISTradesReport_141336_d130240_VOLCKER_NA_BOND_FEED_2013-12-28.txt  VOLCKER_NA_BOND_FEED_2013-12-28.txt
mv MISTradesReport_141337_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-28.txt  VOLCKER_NA_CDS_CRDI_FEED_2013-12-28.txt
mv MISTradesReport_141338_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-28.txt  VOLCKER_EMEA_BOND_FEED_2013-12-28.txt
mv MISTradesReport_141362_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-29.txt  VOLCKER_EMEA_LOANIQ_FEED_2013-12-29.txt
mv MISTradesReport_141363_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-29.txt  VOLCKER_NA_LOANIQ_FEED_2013-12-29.txt
mv MISTradesReport_141364_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-29.txt VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-29.txt
mv MISTradesReport_141365_d130240_VOLCKER_NA_BOND_FEED_2013-12-29.txt  VOLCKER_NA_BOND_FEED_2013-12-29.txt
mv MISTradesReport_141366_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-29.txt  VOLCKER_NA_CDS_CRDI_FEED_2013-12-29.txt
mv MISTradesReport_141367_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-29.txt  VOLCKER_EMEA_BOND_FEED_2013-12-29.txt
mv MISTradesReport_141403_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt  VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt
mv MISTradesReport_141404_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt  VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt
mv MISTradesReport_141405_d130240_VOLCKER_NA_BOND_FEED_2013-12-30.txt  VOLCKER_NA_BOND_FEED_2013-12-30.txt
mv MISTradesReport_141406_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt  VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt
mv MISTradesReport_141407_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-30.txt  VOLCKER_EMEA_BOND_FEED_2013-12-30.txt
mv MISTradesReport_141408_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt
mv MISTradesReport_141409_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt  VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt
mv MISTradesReport_141410_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt  VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt
mv MISTradesReport_141411_d130240_VOLCKER_NA_BOND_FEED_2013-12-30.txt  VOLCKER_NA_BOND_FEED_2013-12-30.txt
mv MISTradesReport_141412_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt  VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt
mv MISTradesReport_141413_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-30.txt  VOLCKER_EMEA_BOND_FEED_2013-12-30.txt
mv MISTradesReport_141414_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt
mv MISTradesReport_141415_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt  VOLCKER_EMEA_LOANIQ_FEED_2013-12-30.txt
mv MISTradesReport_141416_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt  VOLCKER_NA_LOANIQ_FEED_2013-12-30.txt
mv MISTradesReport_141417_d130240_VOLCKER_NA_BOND_FEED_2013-12-30.txt  VOLCKER_NA_BOND_FEED_2013-12-30.txt
mv MISTradesReport_141418_d130240_VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt  VOLCKER_NA_CDS_CRDI_FEED_2013-12-30.txt
mv MISTradesReport_141419_d130240_VOLCKER_EMEA_BOND_FEED_2013-12-30.txt  VOLCKER_EMEA_BOND_FEED_2013-12-30.txt
mv MISTradesReport_141420_d130240_VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt VOLCKER_EMEA_CDS_CRDI_FEED_2013-12-30.txt

Tried below
Code:
ls -1 *.txt|sed 's/\(MISTradesReport_[0-9]*_d130240_\)\(\S*\)/mv \1\2.txt \2/g'

But couldnt get to the output yet
# 2  
Old 12-30-2013
Hello,

The following script may help you.

Code:
##### For test I made 2 files at my system
#### took them in a file
 
$ ls *_2013-12-24.txt > OUTPUT_TXT
$ cat OUTPUT_TXT
MISTradesReport_141105_d130240_VOLCKER_EMEA_LOANIQ_FEED_2013-12-24.txt
MISTradesReport_141106_d130240_VOLCKER_NA_LOANIQ_FEED_2013-12-24.txt
 
 
 
#### Now we are chaging their name as per requirement
 
$ while read line
do
new_VALUE=`echo $line | sed 's/\(.*\)\(VOLCKER_.*\)/\2/g'`
mv $line $new_VALUE
done < "OUTPUT_TXT"
 
 
 
#### After execution of script we can check as follows.
$ ls *_2013-12-24.txt
VOLCKER_EMEA_LOANIQ_FEED_2013-12-24.txt  VOLCKER_NA_LOANIQ_FEED_2013-12-24.txt


NOTE: Script can be run as command without making a ksh or sh script too.



Thanks,
R. Singh
# 3  
Old 12-30-2013
You may try using bash's parameter expansion feature
Code:
for i in *.txt;do 
    mv "$i" "${i/MISTradesReport_[0-9.]*_d130240_/}"
done

# 4  
Old 12-30-2013
if you have Ruby
Code:
ls  MIST* | ruby -e 'ARGF.each{|x|x.chomp!;File.rename(x, x.split("_")[3..-1].join("_")  )  }'

# 5  
Old 01-02-2014
Quote:
Originally Posted by krg.sati
Code:
ls -1 *.txt|sed 's/\(MISTradesReport_[0-9]*_d130240_\)\(\S*\)/mv \1\2.txt \2/g'

But couldnt get to the output yet
There is a typo and a small correction to your code, try as:
Code:
ls -1 *.txt|sed 's/\(MISTradesReport_[0-9]*_d130240_\)\(V.*\)/mv \1\2 \2/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

Search for Pattern as output between the matched String

Hello, I have a file which has the below contents : VG_name LV_name LV_size in MB LV_option LV_mountpoint owner group y testdg rahul2lv 10 "-A y -L" /home/abc2 ... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

Reformat awk output

I need to rearrange the output but i am unable to arrange it to match the format. In the output i need NAME=\"To in the column . Bash: #!/bin/bash cd /cygdrive/c/output/a cat *.txt > output.txt i=/cygdrive/c/output/a/output.csv #echo "NE_Name, Source, Destination, OSPF_AREA_ID"... (4 Replies)
Discussion started by: adgjmpt
4 Replies

4. Shell Programming and Scripting

Alter awk script to reformat output

Data: 0,mfrh_green_screen,1455432969,37540,/prod/test/system/sys/unikixmain.log,3.0M,mfrh_green_screen,3120660,0,36964--37540 0,mfrh_green_screen,1455433269,38100,/prod/test/system/sys/unikixmain.log,3.1M,mfrh_green_screen,3164223,0,37540--38100... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

Using awk to reformat file output

Hi there. I need to reformat a large file. Here is a sample of the file. NETIK0102_UCS_Boot_a,NETIK0102_UCS_Boot_b 5200 2438 70G 5200 2439 70G NETIK0102_UCS_HBA0_a,NETIK0102_UCS_HBA1_b,NETIK0102_UCS_HBA2_a,NETIK0102_UCS_HBA3_b 2673 19D7 55G 2673 19C0 30G 2673 19F5 120G... (5 Replies)
Discussion started by: kieranfoley
5 Replies

6. Shell Programming and Scripting

Shell script to search a pattern in a directory and output number of find counts

I need a Shell script which take two inputs which are 1) main directory where it has to search and 2) pattern to search within main directory all files (.c and .h files) It has to print number of pattern found in main directory & each sub directory. main dir --> Total pattern found = 5 |... (3 Replies)
Discussion started by: vivignesh
3 Replies

7. Shell Programming and Scripting

need awk or sed help to reformat output

We have the following output: server1_J00_data_20120711122243 server1_J00_igs_20120711122243 server1_J00_j2ee_20120711122243 server1_J00_sec_20120711122243 server1_J00_data_20120711131819 server1_J00_igs_20120711131819 server1_J00_j2ee_20120711131819 server2_J00_data_20120711122245... (10 Replies)
Discussion started by: ux4me
10 Replies

8. UNIX for Advanced & Expert Users

Script to reformat output

Hi colleagues, I have the followind script. db2 -x "select substr(TBSPACE,1,20) TABLESPACE from syscat.tables where tabschema = 'SCHEMA' and tabname like '%XXXX' group by TBSPACE order by TBSPACE" | awk '{print $1}' | while read tablespace do db2 "list tablespaces show detail" |grep -p -w... (5 Replies)
Discussion started by: systemoper
5 Replies

9. Shell Programming and Scripting

Split, Search and Reformat by Data Group

Hi, I am writing just to share my appreciation for help I have received from this site in the past. In a previous post Split File by Data Group I received a lot of help with a troublesome awk script to reformat some complicated data blocks. What I learned really came in hand recently when I... (1 Reply)
Discussion started by: mkastin
1 Replies

10. UNIX for Advanced & Expert Users

reformat ps output

I often use "ps -ef" command to list all running processes. Now i want to customize the output to show only 2 parts: CMD and UID as below: /bin/bash /usr/bin/run-parts /etc/cron.weekly root /usr/sbin/httpd apache /usr/sbin/httpd apache /usr/sbin/httpd apache I use ps -ef | awk '{print $8"... (3 Replies)
Discussion started by: fongthai
3 Replies
Login or Register to Ask a Question