Convert a file to another file by the Shell script

I want to convert below input file (abc) to output file (xyz) as below:

$more abc "2005057400BPI","TS.1.BPI.20121112120000.000#S10S#.txt.xml" "2005057408BPI","TS.1.BPI.20121112120000.000#S10S#.txt.xml" "2005057488BPI","TS.1.BPI.20121112120000.000#S10S#.txt.xml" $more xyz "2005057400BPI",TS.1.BPI.20121112120000.000.txt "2005057408BPI",TS.1.BPI.20121112120000.000.txt "2005057488BPI",TS.1.BPI.20121112120000.000.txt 

The abc file contains aorund 35k lines. I am doing the conversion as:

 $perl -pi -e 's/"//g' abc $cut -d'.' -f1-5 abc > xyz $perl -pi -e 's/.....$/\.txt/g' xyz $perl -pi -e 's/#//g' xyz $perl -pi -e 's/^/"/g' xyz $perl -pi -e 's/,/",/g' xyz 

Is there any other way to do this faster with fewer teams.

+4
source share
3 answers

Using Perl:

 perl -plne 's/#.*/.txt/;s/,"/,/;' file 

Add the -i option to update the file.

+2
source

With sed:

 sed 's/"\(TS.*\)#S10S#.txt.xml"/\1.txt/' input 
+2
source

One way: sed :

 sed 's/\(.*,\)"\([^#]*\).*/\1\2.txt/' file 

Results:

 "2005057400BPI",TS.1.BPI.20121112120000.000.txt "2005057408BPI",TS.1.BPI.20121112120000.000.txt "2005057488BPI",TS.1.BPI.20121112120000.000.txt 
0
source

All Articles