Sponsored Content
Top Forums Shell Programming and Scripting Renaming mutiple files with hyphens in name Post 302502293 by mvijayv on Monday 7th of March 2011 02:06:34 PM
Old 03-07-2011
cd to the directory that holds the files

Code:
rm mvcmds.sh
for filename in `ls -1|grep ^fK`
do
NewStr="eStroop_"
OldStr=`echo $filename|awk -F"." '{print substr($1,length($1) -2, length($1))}'`
NewName=""$NewStr""$OldStr"".hdr""
echo "mv $filename $NewName" >> mvcmds.sh
done

If you like the mv commands that are generated in the file mvcmds.sh, run it.
Hope this helps
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Report with mutiple files.

Hi all, In the process of creating CPU reports. I've already used `sar` to create a daily file, then monthly reports for CPU usage (which is averaged across all 4 CPU's). I've now used `cpusar -P ?`(?=CPU#) to collect individual CPU data and have four files for each day which is great. The... (4 Replies)
Discussion started by: Cameron
4 Replies

2. Shell Programming and Scripting

removing mutiple files

I have a script which removes files (if they exist) Here is a cut down example of the script. Variables file1,file2 etc have already been initialized #!/bin/bash if then \rm file1 fi if then \rm file2 fi if then \rm file3 fi if then \rm file4 (9 Replies)
Discussion started by: run_time_error
9 Replies

3. Shell Programming and Scripting

Sending mutiple files thru email to lotus notes

Hi All, I am currently using the following script to send the single file to one/more email addresses. I need to send mutilple files at same time, are there anyway I could modify the script or write new one to accomplish the same. Script *************** #!/bin/ksh # Author: Manish... (4 Replies)
Discussion started by: lapisguy
4 Replies

4. Shell Programming and Scripting

Mutiple For loops - moving files to another directory

I need to clean out some application subdirectories from backup scripts we used to rename to various backup extensions just in case the script failed in production and we need to rollback. I will be moving these old scripts to a staging directory and then removing them after 30 days (I have the... (9 Replies)
Discussion started by: tekster757
9 Replies

5. UNIX for Dummies Questions & Answers

copy mutilple files to mutiple folders

Hi, I just started to learn shell progamming and just can't get my head around the following problem. I need to do the following: I have a folder which contains 100+ subfolders. Inside these subfolders there is one folder named 'Morph' and several jpg's. I need to copy all the files into... (4 Replies)
Discussion started by: M474746
4 Replies

6. UNIX for Advanced & Expert Users

Remove first line from mutiple files

How to remove the first line from multiple files and use it as source to the jobs. Only at the runtime it should remove the first line not in the file . (1 Reply)
Discussion started by: etldeveloper
1 Replies

7. Shell Programming and Scripting

how to replace words in mutiple files under the same directory

I would like to get help to find how to replace word in files from command line instead of to vi to each file. This is the command i am running now. grep <old word> * vi (file with the word found in it) 1,$s/<old word>/<new word>/g It would very helpful if I can combine these in one... (2 Replies)
Discussion started by: ywu081006
2 Replies

8. Shell Programming and Scripting

paste mutiple files in a loop

file1.txt file2.txt file3.txt desired output is each file is in the same directory, hasthe same number of columns but different rows. i want to be able to paste them into one file. thanks! (5 Replies)
Discussion started by: johnkim0806
5 Replies

9. Shell Programming and Scripting

Using grep with hyphens

This is on a RHEL 6 box with bash 4.1.2 I'm trying to to use grep to only find those lines containing matches that form whole words. The -w option works fantastic unless of course that word has a hyphen. The problem is I will get a hit on "test-group" which is a good thing, but I will also... (3 Replies)
Discussion started by: woodson2
3 Replies

10. Shell Programming and Scripting

Split large xml into mutiple files and with header and footer in file

Split large xml into mutiple files and with header and footer in file tried below it splits unevenly and also i need help in adding header and footer command : csplit -s -k -f my_XML_split.xml extrfile.xml "/<Document>/" {1} sample xml <?xml version="1.0" encoding="UTF-8"?><Recipient>... (36 Replies)
Discussion started by: karthik
36 Replies
SUBSTR(3)								 1								 SUBSTR(3)

substr - Return part of a string

SYNOPSIS
string substr (string $string, int $start, [int $length]) DESCRIPTION
Returns the portion of $string specified by the $start and $length parameters. PARAMETERS
o $string - The input string. Must be one character or longer. o $start - If $start is non-negative, the returned string will start at the $start'th position in $string, counting from zero. For instance, in the string ' abcdef', the character at position 0 is ' a', the character at position 2 is ' c', and so forth. If $start is negative, the returned string will start at the $start'th character from the end of $string. If $string is less than or equal to $start characters long, FALSE will be returned. Example #1 Using a negative $start <?php $rest = substr("abcdef", -1); // returns "f" $rest = substr("abcdef", -2); // returns "ef" $rest = substr("abcdef", -3, 1); // returns "d" ?> o $length - If $length is given and is positive, the string returned will contain at most $length characters beginning from $start (depend- ing on the length of $string). If $length is given and is negative, then that many characters will be omitted from the end of $string (after the start position has been calculated when a $start is negative). If $start denotes the position of this trunca- tion or beyond, false will be returned. If $length is given and is 0, FALSE or NULL, an empty string will be returned. If $length is omitted, the substring starting from $start until the end of the string will be returned. Example #2 Using a negative $length <?php $rest = substr("abcdef", 0, -1); // returns "abcde" $rest = substr("abcdef", 2, -1); // returns "cde" $rest = substr("abcdef", 4, -4); // returns false $rest = substr("abcdef", -3, -1); // returns "de" ?> RETURN VALUES
Returns the extracted part of $string; or FALSE on failure, or an empty string. CHANGELOG
+--------------+---------------------------------------------------+ | Version | | | | | | | Description | | | | +--------------+---------------------------------------------------+ |5.2.2 - 5.2.6 | | | | | | | If the $start parameter indicates the position | | | of a negative truncation or beyond, false is | | | returned. Other versions get the string from | | | start. | | | | +--------------+---------------------------------------------------+ EXAMPLES
Example #3 Basic substr(3) usage <?php echo substr('abcdef', 1); // bcdef echo substr('abcdef', 1, 3); // bcd echo substr('abcdef', 0, 4); // abcd echo substr('abcdef', 0, 8); // abcdef echo substr('abcdef', -1, 1); // f // Accessing single characters in a string // can also be achieved using "square brackets" $string = 'abcdef'; echo $string[0]; // a echo $string[3]; // d echo $string[strlen($string)-1]; // f ?> Example #4 substr(3) casting behaviour <?php class apple { public function __toString() { return "green"; } } echo "1) ".var_export(substr("pear", 0, 2), true).PHP_EOL; echo "2) ".var_export(substr(54321, 0, 2), true).PHP_EOL; echo "3) ".var_export(substr(new apple(), 0, 2), true).PHP_EOL; echo "4) ".var_export(substr(true, 0, 1), true).PHP_EOL; echo "5) ".var_export(substr(false, 0, 1), true).PHP_EOL; echo "6) ".var_export(substr("", 0, 1), true).PHP_EOL; echo "7) ".var_export(substr(1.2e3, 0, 4), true).PHP_EOL; ?> The above example will output: 1) 'pe' 2) '54' 3) 'gr' 4) '1' 5) false 6) false 7) '1200' ERRORS
/EXCEPTIONS Returns FALSE on error. Example #5 <?php var_dump(substr('a', 1)); // bool(false) ?> SEE ALSO
strrchr(3), substr_replace(3), preg_match(3), trim(3), mb_substr(3), wordwrap(3), String access and modification by character. PHP Documentation Group SUBSTR(3)
All times are GMT -4. The time now is 10:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy