Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Removing prefix from multiple files and renaming file extension Post 302324242 by jayan_jay on Wednesday 10th of June 2009 09:48:43 AM
Old 06-10-2009
sed 's/^pdb//g;s/.ent/.txt/g' <input-file>
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Renaming multiple files, to get rid of extension

I have a good script to rename multiple files, but what's the best way I can remove some text from multiple filenames? Say I have a directory with 35 files with a .XLS at the end, how can I rename them to remove the .XLS but keep everything the same, without having to mv manually. Thanks. (6 Replies)
Discussion started by: nj78
6 Replies

2. Shell Programming and Scripting

Help removing the prefix of more than 10,000 files

I have more than 10,000 files that all start with "raw_ddd_04_*". How can I remove the prefix on these files in a single command? (8 Replies)
Discussion started by: bbbngowc
8 Replies

3. Shell Programming and Scripting

removing a word in a multiple file starting at the dot extension

hi I would like to ask if someone knows a command or a script on how to rename a multiple file in the directory starting at the end of the filename or at the .extension( i would like to remove the last 11 character before the extension) for example Below is the result of my command ls inside... (5 Replies)
Discussion started by: jao_madn
5 Replies

4. UNIX for Dummies Questions & Answers

Rename multiple files, changing prefix, extension and dropping characters

I'm currently only able to perform some very basic functions, so hope this makes sense... I have a set of about 27 files that need to be renamed from something like this: 000012ABCDEFGHIJ.XXX.YYY.ZZZ 000078KLMNO.XXX.YYY.ZZZ 000099PQ.XXX.YYY.ZZZ to something like this: newa012.abc... (11 Replies)
Discussion started by: bbmcg
11 Replies

5. Shell Programming and Scripting

Renaming the extension of a set of files

Hi All, I am trying to rename the extension of a set of file from .txt to .xtx. When I run the following script, #!/bin/sh l=`ls /f` for f in $l do "mv $f ${f%.txt}.xtx" ; done a file such as 1.txt is renamed to 1? where ? is a strange character. Could you please help me fix the code... (3 Replies)
Discussion started by: sara123
3 Replies

6. Shell Programming and Scripting

Split a file into multiple files with an extension

Hi I have a file with 100 million rows. I want to split them into 1000 subfiles and name them from 1.xls to 1000.xls.. Can I do it in awk? Thanks, (8 Replies)
Discussion started by: Diya123
8 Replies

7. UNIX for Dummies Questions & Answers

Renaming Multiple Files by removing characters

Hi I would like to rename Multiple files in a Unix Directory using Ksh Command. Eg ATT8-2011-10-01 00:00:00-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF needs to be renamed as ATT8-2011-10-01-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF Basically the time... (2 Replies)
Discussion started by: pchegoor
2 Replies

8. Shell Programming and Scripting

Curl command to download multiple files with a file prefix

I am using the below curl command to download a single file from client server and it is working as expected curl --ftp-ssl -k -u ${USER}:${PASSWD} ftp://${HOST}:${PORT}/path/to/${FILE} --output ${DEST}/${FILE} let say the client has 3 files hellofile.101, hellofile.102, hellofile.103 and I... (3 Replies)
Discussion started by: r@v!7*7@
3 Replies

9. Shell Programming and Scripting

Copying multiple files and appending time stamp before file extension

Hi, I have multiple files that read: Asa.txt Bad.txt Gnu.txt And I want to rename them using awk to Asa_ddmmyytt.txt and so on ... If there is a single command or more efficient executable please share! Thanks! (4 Replies)
Discussion started by: Jesshelle David
4 Replies

10. Shell Programming and Scripting

Splitting file into multiple files and renaming them

Hi all, Newbie here. First of all, sorry if I made any mistakes while posting this question in terms of rules. Correct me if I am wrong. :b: I have a .dat file whose name is in the format of 20170311_abc_xyz.dat. The file consists of records whose first column consists of multiple dates in... (2 Replies)
Discussion started by: chanduris
2 Replies
TNEF(3) 						User Contributed Perl Documentation						   TNEF(3)

NAME
Convert::TNEF - Perl module to read TNEF files SYNOPSIS
use Convert::TNEF; $tnef = Convert::TNEF->read($iohandle, \%parms) or die Convert::TNEF::errstr; $tnef = Convert::TNEF->read_in($filename, \%parms) or die Convert::TNEF::errstr; $tnef = Convert::TNEF->read_ent($mime_entity, \%parms) or die Convert::TNEF::errstr; $tnef->purge; $message = $tnef->message; @attachments = $tnef->attachments; $attribute_value = $attachments[$i]->data($att_attribute_name); $attribute_value_size = $attachments[$i]->size($att_attribute_name); $attachment_name = $attachments[$i]->name; $long_attachment_name = $attachments[$i]->longname; $datahandle = $attachments[$i]->datahandle($att_attribute_name); DESCRIPTION
TNEF stands for Transport Neutral Encapsulation Format, and if you've ever been unfortunate enough to receive one of these files as an email attachment, you may want to use this module. read() takes as its first argument any file handle open for reading. The optional second argument is a hash reference which contains one or more of the following keys: output_dir - Path for storing TNEF attribute data kept in files (default: current directory). output_prefix - File prefix for TNEF attribute data kept in files (default: 'tnef'). output_to_core - TNEF attribute data will be saved in core memory unless it is greater than this many bytes (default: 4096). May also be set to 'NONE' to keep all data in files, or 'ALL' to keep all data in core. buffer_size - Buffer size for reading in the TNEF file (default: 1024). debug - If true, outputs all sorts of info about what the read() function is reading, including the raw ascii data along with the data converted to hex (default: false). display_after_err - If debug is true and an error is encountered, reads and displays this many bytes of data following the error (default: 32). debug_max_display - If debug is true then read and display at most this many bytes of data for each TNEF attribute (default: 1024). debug_max_line_size - If debug is true then at most this many bytes of data will be displayed on each line for each TNEF attribute (default: 64). ignore_checksum - If true, will ignore checksum errors while parsing data (default: false). read() returns an object containing the TNEF 'attributes' read from the file and the data for those attributes. If all you want are the attachments, then this is mostly garbage, but if you're interested then you can see all the garbage by turning on debugging. If the garbage proves useful to you, then let me know how I can maybe make it more useful. If an error is encountered, an undefined value is returned and the package variable $errstr is set to some helpful message. read_in() is a convienient front end for read() which takes a filename instead of a handle. read_ent() is another convient front end for read() which can take a MIME::Entity object (or any object with like methods, specifically open("r"), read($buff,$num_bytes), and close ). purge() deletes any on-disk data that may be in the attachments of the TNEF object. message() returns the message portion of the tnef object, if any. The thing it returns is like an attachment, but its not an attachment. For instance, it more than likely does not have a name or any attachment data. attachments() returns a list of the attachments that the given TNEF object contains. Returns a list ref if not called in array context. data() takes a TNEF attribute name, and returns a string value for that attribute for that attachment. Its your own problem if the string is too big for memory. If no argument is given, then the 'AttachData' attribute is assumed, which is probably the attachment data you're looking for. name() is the same as data(), except the attribute 'AttachTitle' is the default, which returns the 8 character + 3 character extension name of the attachment. longname() returns the long filename and extension of an attachment. This is embedded within a MAPI property of the 'Attachment' attribute data, so we attempt to extract the name out of that. size() takes an TNEF attribute name, and returns the size in bytes for the data for that attachment attribute. datahandle() is a method for attachments which takes a TNEF attribute name, and returns the data for that attribute as a handle which is the same as a MIME::Body handle. See MIME::Body for all the applicable methods. If no argument is given, then 'AttachData' is assumed. EXAMPLES
# Here's a rather long example where mail is retrieved # from a POP3 server based on header information, then # it is MIME parsed, and then the TNEF contents # are extracted and converted. use strict; use Net::POP3; use MIME::Parser; use Convert::TNEF; my $mail_dir = "mailout"; my $mail_prefix = "mail"; my $pop = new Net::POP3 ( "pop3server_name" ); my $num_msgs = $pop->login("user_name","password"); die "Can't login: $!" unless defined $num_msgs; # Get mail by sender and subject my $mail_out_idx = 0; MESSAGE: for ( my $i=1; $i<= $num_msgs; $i++ ) { my $header = join "", @{$pop->top($i)}; for ($header) { next MESSAGE unless /^from:.*someone@somewhere.net/im && /^subject:s*important stuff/im } my $fname = $mail_prefix."-".$$.++$mail_out_idx.".doc"; open (MAILOUT, ">$mail_dir/$fname") or die "Can't open $mail_dir/$fname: $!"; # If the get() complains, you need the new libnet bundle $pop->get($i, *MAILOUT) or die "Can't read mail"; close MAILOUT or die "Error closing $mail_dir/$fname"; # If you want to delete the mail on the server # $pop->delete($i); } close MAILOUT; $pop->quit(); # Parse the mail message into separate mime entities my $parser=new MIME::Parser; $parser->output_dir("mimemail"); opendir(DIR, $mail_dir) or die "Can't open directory $mail_dir: $!"; my @files = map { $mail_dir."/".$_ } sort grep { -f "$mail_dir/$_" and /$mail_prefix-$$-/o } readdir DIR; closedir DIR; for my $file ( @files ) { my $entity=$parser->parse_in($file) or die "Couldn't parse mail"; print_tnef_parts($entity); # If you want to delete the working files # $entity->purge; } sub print_tnef_parts { my $ent = shift; if ( $ent->parts ) { for my $sub_ent ( $ent->parts ) { print_tnef_parts($sub_ent); } } elsif ( $ent->mime_type =~ /ms-tnef/i ) { # Create a tnef object my $tnef = Convert::TNEF->read_ent($ent,{output_dir=>"tnefmail"}) or die $Convert::TNEF::errstr; for ($tnef->attachments) { print "Title:",$_->name," "; print "Data: ",$_->data," "; } # If you want to delete the working files # $tnef->purge; } } SEE ALSO
perl(1), IO::Wrap(3), MIME::Parser(3), MIME::Entity(3), MIME::Body(3) CAVEATS
The parsing may depend on the endianness (see perlport) and width of integers on the system where the TNEF file was created. If this proves to be the case (check the debug output), I'll see what I can do about it. AUTHOR
Douglas Wilson, dougw@cpan.org perl v5.12.1 2002-02-24 TNEF(3)
All times are GMT -4. The time now is 11:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy