Sponsored Content
Top Forums Shell Programming and Scripting Renaming by manipulating strings Post 302718887 by msabhi on Sunday 21st of October 2012 11:09:56 AM
Old 10-21-2012
Quote:
Originally Posted by mc2z674gj
Code:
ls *ext | perl -F"--" -alne '{if($#F==1){ 
if($F[1]=~/(\d+).ext/){ $p=$1;$F[0]=~s/^/$p /g;$F[1]=~s/$p//;print "mv \"$_\" \"".join(" -- ",@F)."\"" ;} 
else { ($F[0],$F[1])=($F[1],$F[0]);$F[0]=~s/(.ext|^ *)//;$F[1]=~s/ *$/.ext/;print "mv \"$_\" \"".join(" -- ",@F)."\"" ;} 
}else{ ($F[0],$F[2])=($F[2],$F[0]);$F[0]=~s/(.ext|^ *)//;$F[2]=~s/ *$/.ext/;;print "mv \"$_\" \"".join(" -- ",@F)."\"" ;} 
}' | sh

for moving numeric to the beginning, this script works perfectly !
I believe this script works for all your conditions..

???
i have a question can the script is capable to rename directories
Can you please give me some examples before i can answer you...
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Manipulating two files

Hi Friends, I prefer to represent my problem with example. I have two files as below: file1.txt --------- abcd.....1234......XY abcd.....1235......XX abcd................. abcd...231236..1111YX abcd...241236..1112YY abcd...241237......YY abce.....1235......YY file2.txt ------- ... (4 Replies)
Discussion started by: rinku11
4 Replies

2. Solaris

Manipulating File

Help...please. I have a log that contains Warning Authentication Failed: User GHDT88998HS doesn't exit: The User GHDT88998HS could not be found Mar 22, 2008 5:22:22AM com.hometel.ttm.auth.userlogin. about maybe a thousand entries failed user acct message How can I grab just the username... (2 Replies)
Discussion started by: rivendell500
2 Replies

3. UNIX for Dummies Questions & Answers

Help!! manipulating file

Hi all, I need help manipulating the file below. Here is what I needed to do. First, I have to replace INSUPD to DELETE. Then I need to change the content of the file around by flipping the contents in the file from the bottom to the top (start from "CMD") How should I attack this? Here... (2 Replies)
Discussion started by: sirrtuan
2 Replies

4. Windows & DOS: Issues & Discussions

Renaming files with strings from xml tags

Hello! I need to rename 400+ xml files. The name of the specific file is contained in a xml tag in the file itself. The batch file should rename all these files with strings found in xml tags. Every xml file has the following tags: <footnote><para>FILENAME</para></footnote> I have to get... (3 Replies)
Discussion started by: degoor
3 Replies

5. Shell Programming and Scripting

Manipulating a file

Hi everybody, I need an urgent help with a BASH script. I have file which contains (besides the other data) the lines with the following structure identified by with keyword PCList: <PARAMETER NAME="PCList" TYPE="LIST_STRUCTURE" MODEL="{,}" ... (1 Reply)
Discussion started by: sameucho
1 Replies

6. UNIX for Dummies Questions & Answers

Delete strings in file1 based on the list of strings in file2

Hello guys, should be a very easy questn for you: I need to delete strings in file1 based on the list of strings in file2. like file2: word1_word2_ word3_word5_ word3_word4_ word6_word7_ file1: word1_word2_otherwords..,word3_word5_others... (7 Replies)
Discussion started by: roussine
7 Replies

7. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

8. Programming

Code imrovements on manipulating strings

I have written the code below and would be very grateful for any comments about it (how can I improve it, simplify it,...). #ifndef String_hh #define String_hh #include <stdio.h> #include <string.h> #include <stdlib.h> #include "Vect2.hh" #include "Vector.hh" #include... (0 Replies)
Discussion started by: kristinu
0 Replies

9. Shell Programming and Scripting

Manipulating files

Not sure if the question posted in another forums can be moved by me.So posting the link here. https://www.unix.com/unix-advanced-expert-users/221425-shell-script-manipulate-files.html#post302795379 Need your help here. (1 Reply)
Discussion started by: vedanta
1 Replies

10. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies
GPIV_SERIES(1)						      General Commands Manual						    GPIV_SERIES(1)

NAME
gpiv_series - Script for (parallel) processing a series of numbered files. SYNOPSIS
gpiv_series [-a | --arg_n] [-b | --basename FILE] [-e | --ext ext] [-f | --first N] [-l | --last N] [-i | --incr N] [-x|| --prefix] [-h | --help] [-n | --none] [-p | --print] [--pad] "process -key1 ..." DESCRIPTION
gpiv_series processes a series of numbered files. If no parameters are defined at the command line, standard parameters will be used that are defined in the script. Principally, any program or script may be invoked by gpiv_series. "Process" is a string which represents the name of the program to be executed, including eventually command line options and arguments. The file to be processed, as constructed from -b c.s., will be appended to the "process" string. If the program has to be feeded with -f "filename", write -f at the end of the string. When using the parallelised version, mpipython is invoked and the script may be launched with mpirun. The script needs that all input files are accessible on each node by copying all data or by (NFS) mounting the File System containing the input data on each node. This program does not use the parameter resources from libgpiv. Options -a | --arg_n If the process needs the current number in its argument list instead of prepending/appending it to the FILE, the number will be put before (-f) filename in the "process" string. -b | --basename FILE The FILE has to be given without its extension. FILE represents the file name without its number. It is supposed that the leading or ending number in the filename is the counter that will be applied by gpiv_series when processing. -e | --ext EXT add an extension EXT after the filename (without the leading ".") in "process". -f | --first N Defines the counter N of the number at which the analyses starts. Default: 0. -l | --last N The last number N that will be processed. Default: 0. -i | --incr N Increment number with N. Default: 1. This might be useful, for example, if subsequent numbered images are combined for cross-corre- lation with the gpiv_img2gpiv tool. -x | --prefix Use prefix numbering to file basename. -h | --help On-line help. -n | --none Suppresses real execution, only prints the process to stdout. -p | --print Prints the process to be performed on each file to stdout. --pad N Padding a number with N zero's when combining with the filename. SEE ALSO gpivtools NOTES
AUTHOR
Gerber Van der Graaf BUGS
The parallelised script has only been tested with the LAM version of mpipython. 19 Januari 2005 GPIV_SERIES(1)
All times are GMT -4. The time now is 06:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy