Results 1 to 4 of 4
say I input aaa.f and I need to separate it into aaa and f, and then attach .f90 to aaa to form aaa.f90. How can that be most easily done? ...
- 12-14-2011 #1Just Joined!
- Join Date
- Nov 2011
- Posts
- 13
easy way to separate different fields?
say I input aaa.f and I need to separate it into aaa and f, and then attach .f90 to aaa to form aaa.f90. How can that be most easily done? Thanks,
- 12-14-2011 #2
I would write it in PERL, and I would use the split function, splitting at the dot. Then joining the two variables. It might look something like this.
Of course, you'd have to change it up to match how your input will be added.Code:$input = "aaa.f"; $ext= "f90" ($name, $discard) = split('.', $input); $desired = join('.',$name,$ext); print $desired;linux user # 503963
- 12-14-2011 #3
Yes, perl or any other language is a possibility, as it enables all kind of further processing.
For a one shot solution, a sed oneliner might also be suitable:
You will need to adjust the regex to your actual usecase.Code:echo aaa.f | sed 's#^\(aaa\)\.f$#\1.f90#' aaa.f90
You must always face the curtain with a bow.
- 12-15-2011 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
It looks like you are renaming old Fortran filenames to new filenames.
If you are using bash or ksh, you can use:
producingCode:$ v="faaf.f" $ echo ${v/.f/.f90}
I used versions:Code:faaf.f90
This is all done within the shell as opposed to running external commands, but for a small amount of data, the difference is probably not significant. Examples of these kinds of internal manipulations can be seen at BashFAQ/100 - Greg's WikiCode:GNU bash 3.2.39 ksh 93s+
Using this construct in a mv command should solve your problem. If indeed you are renaming files, you might be able to use rename:
The "no-act" shows what would happen, and, when you are satisfied that it will do what you desire, the "no-act" should be removed to actually perform the rename. As I have done here, you can try that in a separate directory on test filenames.Code:$ touch faaf.f $ ls -lgG *.f -rw-r----- 1 0 Dec 15 04:21 faaf.f $ rename --no-act 's/\.f$/.f90/' *.f faaf.f renamed as faaf.f90
See man pages for details.
Best wishes ... cheers, drlLast edited by drl; 12-15-2011 at 09:32 AM.
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote