f



How to rename files and contents of the file

Hi,

I have two files 
XYZ_INPUT_FILE_ABCD.YYYYMMDD
XYZ_INPUT_CONTROL_ABCD.YYYYMMDD

In Shell script i have to change the character "_" before ABCD wit
dot(.)
It should be like this
XYZ_INPUT_FILE.ABCD.YYYYMMDD 
XYZ_INPUT_CONTROL.ABCD.YYYYMMDD 
and also inside the second file XYZ_INPUT_CONTROL_ABCD.YYYYMMDD th
first file name (XYZ_INPUT_FILE_ABCD.YYYYMMDD) is present. So i have t
change the character "_" before ABCD with dot(.)

Could you please help me out on this. I appreciate your help i
advance. 
Thanks
Chinn

--
chinn
-----------------------------------------------------------------------
chinna's Profile: http://fantasticunix.com/forum/member.php?userid=4
View this thread: http://fantasticunix.com/forum/showthread.php?t=50620

0
7/7/2008 3:38:48 AM
comp.unix.shell 15484 articles. 3 followers. Post Follow

2 Replies
797 Views

Similar Articles

[PageSpeed] 51

chinna;2594880 Wrote:
> Hi,
> 
> I have two files 
> XYZ_INPUT_FILE_ABCD.YYYYMMDD
> XYZ_INPUT_CONTROL_ABCD.YYYYMMDD
> 
> In Shell script i have to change the character "_" before ABCD wit
> dot(.)
> It should be like this
> XYZ_INPUT_FILE.ABCD.YYYYMMDD 
> XYZ_INPUT_CONTROL.ABCD.YYYYMMDD 
> and also inside the second file XYZ_INPUT_CONTROL_ABCD.YYYYMMDD th
> first file name (XYZ_INPUT_FILE_ABCD.YYYYMMDD) is present. So i have t
> change the character "_" before ABCD with dot(.)
> 
> Could you please help me out on this. I appreciate your help i
> advance. 
> Thanks
> Chinn
echo "XYZ_INPUT_FILE_ABCD.YYYYMMDD" | tr _ABCD .ABCD

try this one. You can replace the file name string in the echo

--
mrrij
-----------------------------------------------------------------------
mrrijo's Profile: http://fantasticunix.com/forum/member.php?userid=2
View this thread: http://fantasticunix.com/forum/showthread.php?t=50620

0
mrrijo
7/7/2008 6:09:14 AM
Sorry, "tr" will do it wrong.
But sed will do it correct. 

echo "XYZ_INPUT_FILE_ABCD.YYYYMMDD"|sed 's/_ABCD/.ABCD/

--
mrrij
-----------------------------------------------------------------------
mrrijo's Profile: http://fantasticunix.com/forum/member.php?userid=2
View this thread: http://fantasticunix.com/forum/showthread.php?t=50620

0
mrrijo
7/7/2008 6:26:06 AM
Reply:

Similar Artilces:

how to make a file from the strings in a file and redirect the content to these new files
Here is scenari0 223 files copied to this this one big flat file. now how to make this file to 223 files. further explaination: below is excerpt from that one file under xxxxx you will see @TC_ID: :BIC4007 then another @TC_ID: :BIC40008 and has a 223 time with TC_ID: :BICxxx numbers How do I use such a script that makes a file named BIC40008, then another BIC40007 AND copying the content from line @TC_ID: :BIC40007 till one line before the next TC_ID: :BIC40008 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx @TC_ID: :BIC40007 @TC_TITLE: @ACT_IDS: @AUTHOR: @AUTO: @CLASS: @GROUP_ID: @RELEASES: @T...

how to append contents to an existing file contents at the end of file?
Hi all   I am Kiran, working with LV8.0  FDS   I find difficulty while trying to add new file contents(some messages)  to an existing file at the end /begining of a file.   Whenever i try to do that,it is replacing the previous contents,but i dont need that. i want the contents to be appended.   Plz suggest me.   thanks & regards        kiran ...

Renaming files (about 1000 files)
hi! I have a bunch of files (music samples) I need to rename before converting them. [b]My structure is :[]/b folder1/subfolder1/list of files.extension (minimum 5 files) folder2/subfolder2/list of files.extension .... folder65/subfolder65/list of files.extension [b]The files are like (in each folders) :[/b] 01 filename.extension 02 filename.extension etc... What I would like to do is renaming all of those files with this structure : folder1 - subfolder1 - file 1.extension [b]Example[/b] From : /Project 1/Guitar/01 Guitar lick.wma To : /destination/Project 1 - Guitar - 01 Guitar lic...

split file contents into files
I have extracted some scripts from an Oracle database using the Toad query below. The script body is of datatype HUGHCLOB; which means each script may be from 50 - 200+ lines. N.B. Toad is a tool to query oracle database. select script_name , script_type , '>>>>>' , script_body from script_table order by script_type, script_name; The Toad query returned a single text file like this below. What I want is an shell script, say, AWK, to parse this all-in-one TOAD output file, to split each script into its own script files, with names being script_name1.txt, script_name2.txt, ... etc. Any help appreciated. -- script_name1,TypeA,>>>>>, ;comment line 1 ;comment line 2 <blank line> script 1 line 1 script 1 line 2 ..... scrtp 1 last line script_name2,TypeB,>>>>>, /* * comments for script 2 * ... */ script 2 line 1 script 2 line 2 .... -- TIA On 5/31/2012 9:05 PM, Harry wrote: > I have extracted some scripts from an Oracle database using > the Toad query below. The script body is of datatype HUGHCLOB; > which means each script may be from 50 - 200+ lines. > N.B. Toad is a tool to query oracle database. > > > select > script_name > , script_type > , '>>>>>' > , script_body > from > script_table > order by > script_type, ...

file extention from file file location
Hi, I am new to perl (only working on this one problem) but I program in other languages. We have an upload script written in cgi. Can anyone tell me how to get the file extension from the variable $File1 (actual file location on uploader's computer) then find out if it is equal to "txt" Thanks in advance for not telling me to read the manual. Ron -- PLEASE NOTE: comp.infosystems.www.authoring.cgi is a SELF-MODERATED newsgroup. aa.net and boutell.com are NOT the originators of the articles and are NOT responsible for their content. HOW TO POST to co...

Iteration through File.file? misses entries for which File.file?(entry) == true
Hello everyone, I'm new to Ruby, so I'm most likely making an elementary mistake. However, searching Google didn't help me find my answer, and after mucking around with irb I still haven't figured it out. I wrote a method that was intended to take all of the files in a given directory and put them into an array. Here's the code I wrote: def getFiles(dir) pwdFiles = Array.new Dir.foreach(dir) do |entry| pwdFiles.push(entry) if File.file?(entry) == true end end This works fine when called on the working directory --- that is, getFile...

Renaming files by counting the number of files
SCO OpenServer 5.0.5 all patches, etc.... I have a process that I need to run more than once a day (as it was originally designed) This process creates a directory with the julian date in it... i.e. /u/home/data/bcu253 once my program runs, there will be files there as such: 09090401.tar 09090402.tar 09090403.tar as you can see these are in mmddyy[01-99].tar format....depending on how many records it finds, it can make only 1 tar file or at the max it will make 10 of them.... So, at this point I have this directory: /u/home/data/bcu253 and I have the files in this directory called: 09090401.tar 09090402.tar etc, etc What I'd like to do now, before the process runs again in about 4 hours (or whenever I tell it to via cron) is move the files to a nested directory under here.... i.e. I want to create /u/home/data/bcu253/bcu253a and move the tar files into that directory so I would have this: doing an 'l' in this directory /u/home/data/bcu/253 you should now only see the directory drwxr-xr-x 2 root sys 512 Sep 9 15:58 bcu253a and in that directory (bcu253a) would be the tar files I just put there... Now, the next time I run this process, I want to somehow look up the number of tar files that sit nested in the bcu253a directory...... i.e. if the first time I run the program, it creates 5 tar files, 09090401.tar thru 09090405.tar the second time it runs, it will create tar files again, just in the /u/home/data/bcu253 directo...

ssis
I have a table, that has a column which determines the file name. I want to export a file and rename it immediately. For Ex: Select Id, count(*) from Mytable group by ID gives the following: ID Count 1 100 2 200 4 50 Now in my SSIS package, I am able to create a Execute SQL task (Select distinct ID from MyTable), followed by a For Each loop container. Inside the For Each loop container, I have a OLE DB source and a flat file destination. OLE DB source has the following: select top 10 * from MyTable where id =?. I am able to eport file for ID=1. Then it gets replaced by file for ID=2 which then gets replaced by file for ID = 4. So I want the test.txt to be renamed to test1.txt, test2.txt and text4.txt. I tried using File system task or Execute process task. It did not work. Please let me know how I could make it work. Thank you for your help. ...

PHP File upload
Hi, I have to allow my visitors to upload image on my site. I am using the follwoing code to do that: $uploaddir = 'admin/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); My problem is that I expect them to use same file name, like all of them will be uploading files like, comments.rtf. So if there is already one comments.rtf the file will get overwriten... so the challenge is to rename the files to username-filename.rtf can anybody here will take the pain to modify this code, I will be thankful, or please guide to me some tutorial where they are dealing with simple code and not with advanced classes. Thank you in advane Regards, Jaunty Edward I noticed that Message-ID: <1103007641.349701.201220@f14g2000cwb.googlegroups.com> from smilesinblues@hotpop.com contained the following: > >$uploaddir = 'admin/'; >$uploadfile = $uploaddir . basename($_FILES['userfile']['name']); >move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); > >My problem is that I expect them to use same file name, like all of >them will be uploading files like, comments.rtf. So if there is already >one comments.rtf the file will get overwriten... so the challenge is to >rename the files to username-filename.rtf Is the username unique? If so it's just $uploadfile = $uploaddir. $username....

Replace some stuff in the file with the contents in a file.
Hi all, I've two files, say, file1 and file2. File1 has the following content: ------------- blabla .... The_beginning_mark_of_inserting_file2 here_comes_the_stuff_want_to_be_replaced_by_file2's_content The_end_mark_of_inserting_file2 .... blabla ------------------- From my above description, you can find that I want to replace the specific content in file1 with file2. Any hints on this issue? Regards. -- ..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. On 5/2/2011 1:06 AM, Hongyi Zhao wrote: > Hi all, > > I've two files, say, file1 and file2. Fi...

Batch file to Shell file
I have given my batch . CAn anyone please convert this into Shell file. It is v urgent. @echo off REM Locations set Enigma_Home=D:\Enigma3C set Vin_Home=D:\VIN_Test_Suite\VIN set PartSet_Home=D:\VIN_Test_Suite\PartSet REM Pre_Process set Vin_Desc=Ford_Vin_Descriptor.xml set Vin_Desc_out=Ford_Vin_out_Descriptor.xml set PartSet_Desc=Ford_PartSet_Descriptor.xml set PartSet_Desc_out=Ford_PartSet_out_Descriptor.xml REM Create Packs set VIN_title_Name=FordSample set PartSet_title_Name=PartSetSample set Work_Dir=D:\VIN_Test_Suite\WorkFiles set PACKS_DIR=D:\VIN_Test_Suite\Packs REM For Update ...

Filtering files in GetOpenFileName by file content
Is it possible to extend the GetOpenFileName dialog so that it will filter by file CONTENT as well as filename extension? For example, so that it will list *.AVI files, but only those containing DV data. Or is there another way to do this? Thanks I took a quick look at the documentation and it says to set lpfnHook and OFN_ENABLEINCLUDENOTIFY and respond to the CDN_INCLUDEITEM message. On 8 Dec 2003 04:06:10 -0800, cbdeja@my-deja.com (-) wrote: >Is it possible to extend the GetOpenFileName dialog so that it will >filter by file CONTENT as well as filename extension? ...

object files, header files, source files?
I can't find any books describing the anatomy of C/C++ programs. What is an object file? Can it be generated from a header file?, what is linking?, why does a source file need an object file? etc. I have looked in The C programming Language, The C++ Programming Language, Accelerated C++, GNU make etc but they don't describe these basic subject. Any literature that covers these subjects? saneman wrote: > I can't find any books describing the anatomy of C/C++ programs. What is > an object file? Can it be generated from a header file?, what is > linking?, why does a s...

write file + input file + write file
Hi, I want to write some latex command to a file (file1), input the file at the end of the document. These command shall write to another file (file2) and at a second run I use the file2. Whatever I have tried nothing works and I don't known why. The goal is to save a set of special commands and run them at the end of the document, because they use some values which are only available at the end! Can anybody please help me with that? Thanks in advance! I should be something like: \begin{document} \usepackage{style} \input{file2} %file exists from a previous run \end{document} style.sty: \newwrite\fileone \openout\fileone=file1.out \newwrite\filetwo \openout\filetwo=file2.out \newcommand{\writetofiletwo}[1]{% \write\filetwo{#1}% } \newcommand{\writetofileone}[1]{% \write\fileone{\writetofiletwo{some text}}% } \AtEndDocument{\closeout\fileone% \input{file1}% \closeout\filetwo% } Problem solved :-) \immediate\closeout before \input was required. greenux wrote: > Hi, > I want to write some latex command to a file (file1), input the file > at the end of the document. These command shall write to another file > (file2) and at a second run I use the file2. > Whatever I have tried nothing works and I don't known why. The goal is > to save a set of special commands and run them at the end of the > document, because they use some values which are only available at the > end! > Can anybody please help me with that? > Thanks in advance! &...

UNIX header files to Windows header files
Hi, I need to port some C code from UNIX SGI to Windows (MS VC++ compiler). The following header files arent available in windows: #include <sys/param.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/socketvar.h> #include <netinet/in.h> #include <sys/types.h> #include <sys/stat.h> #include <netdb.h> #include <arpa/inet.h> Does anyone have any suggestions on how to get windows versions of these? Thanks! anand.ba@gmail.com wrote: > > I need to port some C code from UNIX SGI to Windows (MS VC++ compiler). &g...

Script to rename file to text extracted from file.
I have hundreds of lscfg files that are named with all sort of names . I would like to rename each file to the serial number in each file . I first sorted the files in to power rspc and chrp Only intrested in the chrp machines at this time I can creat a file with a list of the files in it . ( chrplist ) I can get the serial number . grep "Machine/Type" $filename | cut -d . -f 5 My problem is i can't seem to handel 2 varables example While read filename; do grep "Machine/Type" $filename | cut -d . -f 5 > newname cp $filename $newname done < chrplist I know this does not work and this is not even close to all the things i have tried a lot of other methods . I can do the renames by hand but what a pain if this was a one time thing i would not worry to much bt i get these files in often and makes ti a lot easie rto do compares and maintain the lateset configuration files if they are all named by their serial number. Any pointers would be appreciated. Andy <noname@nowhere.net> writes: After a tiny modification it *should* work: while read filename; do newname=`grep "Machine/Type" $filename | cut -d . -f 5` cp $filename $newname done < chrplist Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. On Fri, 11 Aug 2006 20:29:14 -0700, Paul Pluzhnikov <ppluzhnikov-nsp@charter.net> wrote: >Andy <noname@nowhere.net> writes: > >After a tiny modif...

Rename file an existing file in loop 1954525
hi I want to rename an existing file (fixed.dat) each time it is created. may be fixed1.dat fixed2.dat and so on On 12/12/2012 8:19 AM, harishameed_33 wrote: > hi > > I want to rename an existing file (fixed.dat) each time it is created. > > may be fixed1.dat > fixed2.dat and so on .... Why not simply create it w/ the desired name instead? Use an internal WRITE to generate a name dynamically... character(len=20) :: fname do i=1,N write(fname,'("fixedI2.dat")') i open(11,fname) ! whatever to do w/ LUN 11 close(11) enddo Salt to suit... -- On 12/12/2012 1:00 PM, dpb wrote: .... > write(fname,'("fixedI2.dat")') i .... > Salt to suit... Such seasoning to included the format I2.2 above instead of just I2 to write the leading 0 in the name. And, of course, fixing the width appropriately for the size of the maximum number expected. -- On 2012-12-12 16:36:35 -0400, dpb said: > On 12/12/2012 1:00 PM, dpb wrote: > ... > >> write(fname,'("fixedI2.dat")') i > ... > >> Salt to suit... > > Such seasoning to included the format I2.2 above instead of just I2 to > write the leading 0 in the name. > > And, of course, fixing the width appropriately for the size of the > maximum number expected. Some folks prefer that the I2.2 be a format item and not part of ...

Executable file for .m files for Cluster/UNIX
Hi all, I have a set of .m files which run successively to generate output matrix. I need to run all these .m files on cluster/UNIX. How do I write an executable file for this? Help would be appreciated. ...

Reading contents of an excel file from a test file
Hi I am writing a script to read various file types (doc, xls, pdf, html etc.) and search for certain keywords. Without caring for the file formats, I used 'findstr' system call from perl with the keyword for each file and directed the output to a text file. The results were not as bad as I had expected :) In the txt file created, I have the list of all the files and the original text from the file where the string to be searched occurs but this file has some unicode characters which prevents it to be read and processed properly. :( I basically get a lot of "" in the result test file which makes perl act wierd. Can u please suggest a way to read a text file which has unicode characters?? I do NOT want to create seperate parsers for the different file types (things like ParseExcel) as it will increase the complexity and will need a lot of effort. Cheeeeers!! KRN!!?! sorry guys.. but the unicode characters as they appear as rectangles in my text file (all appear as the same), are not printed when posting a message on this forum!! On May 15, 11:49 am, Mick <karanarora...@gmail.com> wrote: > Hi > > I am writing a script to read various file types (doc, xls, pdf, html > etc.) and search for certain keywords. Without caring for the file > formats, I used 'findstr' system call from perl with the keyword for > each file and directed the output to a text file. The results were not > as bad as I had expected :) > In the ...

how to convert dos file to unix file in eclipse
I am working on dos environment for some java files but need to check in to unix sytem.how to convert dos file to unix file in eclipse? Thanks, David "david wolf" <yihucd@gmail.com> wrote in message news:1145547009.141508.69230@z34g2000cwc.googlegroups.com... >I am working on dos environment for some java files but need to check > in to unix sytem.how to convert dos file to unix file in eclipse? It's probably easier if you use a seperate tool rather than Eclipse for this task. Within Eclipse, you can right click on the project and choose "properties&q...

File.renameTo(File)
Thanks, I'm running 1.5 version of java and I'm simply attempting to move a file from a source directory to a target directory. It seems the renameTo works fewer times than it does. I print the absolute path to ensure they're correct and they are. Someone mentioned there's a renameTo bug. Is there a workaround? I'm thinking of exec'ing a process and running a dos move. Thank again. Sly On Tue, 4 Apr 2006 20:38:18 -0400, ":-o" <fcrutch@save-net.com> wrote, quoted or indirectly quoted someone who said : > >It seems the renameTo works few...

Unix files saved in a D3 file save are changed
Hello All: When I restore an account where the D3 file is actually a Q-pointed Linux directory, a line containing the name of the Linux file is inserted before the rest of the file item. Does anyone know why or how to avoid this? D3 item looks like this: :ED MD DS2.UQ.BIN top ..P 001 QS 002 003 /dsol/dscope/da/bin eoi 003 Linux file before restore: :ED DS2.UQ.BIN mvhttp-client top ..P 001 #!/usr/bin/perl 002 # 003 # Copyright (C) 2015... Linux file after restore: :ED DS2.UQ.BIN mvhttp-client top ..P 001 mvhttp-client 002 #!/usr/bin/perl 003 # 004 # Copyright (C) 2015... System info: D3 Version: D3 lx-7.5.12-.Z Linux Version: RedHat Enterprise Linux (RHEL) 5.2 x64 running kernel 2.6.18-92.1.22.el5PAE Running on: Dell PowerEdge 1900 with dual Intel Xeon E5320 processors with a PERC 5/i RAID controller in (I believe) RAID 5 configuration I'd ask this question on the Pick & Multivalue group on google, as this newsgroup is essentially defunct First port of call wuld be to upgrade D3 ... at least to latest versions in 7.5.x, if not beyond to 9.x --> check release notes as this could be an issue that was/is resolved ...

rename to txt file
I am trying to rename a file in my directory. I can see this file in directory. It has an extention of .dep, when I attempt to rename it, nothing gets renamed. When I output all filenames from the directory this particular file containing .dep is not on the list. I can see it is there, however this script doesn't pull it. Do you know what this might mean? require 'fileutils' require 'find' require 'ftools' require 'enumerator' #locate new .dep file and rename to txt file for later modification Dir.entries("C:/Diff").each do |filename| if File.e...

Random file in a file
I am trying to take a random file from a folder what can I do to get random to find a file but not numbers? On Tue, 20 Oct 2015 19:24:03 +0000, Baldvin Vigfússon wrote: > I am trying to take a random file from a folder what can I do to get > random to find a file but not numbers? You could get a list of files in the folder, generate a random integer between 1 and the number of files, then use that RN to index the file list. Bruce ...

Web resources about - How to rename files and contents of the file - comp.unix.shell

Help:Contents - Wikipedia, the free encyclopedia
Templates are special pages that contain boilerplate text intended to be displayed on more than one page in Wikipedia. This Tip of the day box ...

Portal:Contents/Society and social sciences - Wikipedia, the free encyclopedia
A society is a group of people who form a semi-closed system . At its simplest, the term society refers to a large group of people sharing their ...

World Twenty20: David Warner content to bat at No.4 but line-up 'still open'
The vice-captain endorses his positioning by captain Steve Smith as the team prepares for clutch games against Pakistan and India in Mohali. ...

Opinion: Apple Music in major need of search improvements as Apple plans more original video content
... Apple to begin addressing the issues that were introduced. The most exasperating part of Apple Music on iOS has to be searching for video content. ...

Viceland Creates VR Content for Samsung
Viceland is creating virtual reality content for Samsung as part of a larger ad deal that will make some of its primetime programming commercial-free. ...

Sitefinity delivers improved content management and customer analytics
In modern fast-moving business environments, marketers need to be able to respond quickly to changes and deliver appropriate content. To help ...

Netflix’s catalog of content is shrinking, but that’s not a bad thing
The U.S. Netflix catalog is highly coveted by international subscribers who aren’t happy with what local Netflix lineups have to offer. Indeed, ...

This virtual reality company wants to change the way content is developed
... Ventures. Bubba Muraka, a DFJ partner, will also receive a seat on Visionary VR’s board. Visionary VR's goal is to help virtual reality content ...

Critical Content Tunes Into ‘Radio Gaga’ With ‘Catfish’ Duo; Sky Takes Stake In Sugar Films – Global ...
Amsterdam-based indie distributor Lineup Industries has sold two formats to Critical Content which launched in January under former Relativity ...

Advanced Metrics for Content Marketing Experts
Advanced Metrics for Content Marketing Experts written by Alex Boyer read more at Duct Tape Marketing Metrics can be tedious and overwhelming ...

Resources last updated: 3/29/2016 1:43:41 AM