Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How can I rename multiple files depending on a string occuring in the filenames? Post 302118470 by karman on Tuesday 22nd of May 2007 08:05:45 AM
Old 05-22-2007
There is a built-in Linux utility "rename" that does the trick

I discovered that my Linux comes with the "rename" utility.
Usage: "rename inputstring newstring"

But good to know how to write a script yourself.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to backup multiple files and amend their filenames

Hi, I'm trying to write a command that backs up certain files into my current directory and adds a prefix to the backed up file name. I realise this can be done in a script by specifying each individual file but would like to know if it can be done on one line and made an alias. I have the... (5 Replies)
Discussion started by: m223464
5 Replies

2. Shell Programming and Scripting

Split file into multiple files depending upon first 4 digits

Hi All, I have a file like below: 1016D"ddd","343","1299" 1016D"ddd","3564","1299" 1016D"ddd","3297","1393" 1016D"ddd","32989","1527" 1016D"ddd","346498","1652" 2312D"ddd","3269","1652" 2312D"ddd","328","1652" 2312D"ddd","2224","2100" 3444D"ddd","252","2100" 3444D"ddd","2619","2100"... (4 Replies)
Discussion started by: deepakgang
4 Replies

3. Shell Programming and Scripting

extract multiple cloumns from multiple files; skip rows and include filenames; awk

Hello, I am trying to write a bash shell script that does the following: 1.Finds all *.txt files within my directory of interest 2. reads each of the files (25 files) one by one (tab-delimited format and have the same data format) 3. skips the first 10 rows of the file 4. extracts and... (4 Replies)
Discussion started by: manishabh
4 Replies

4. Shell Programming and Scripting

write to multiple files depending on file type (solved)

I want a script that will add comments to a file before check-in files. comments depend on type of files. i have a script to list files in the directory that will be checked-in There are xml, js, html, vm files. vm will use comments like c/c++ ( // or /*..*/) can you help me add a comment line... (0 Replies)
Discussion started by: pradeepmacha
0 Replies

5. UNIX for Dummies Questions & Answers

Rename Multiple Files

Hey guys, I am the definition of a newbie. I am in the process of trying to rip all my dvds onto a new HTPC I setup. While doing this, I am also trying to organize a bunch of other files I already have to proper naming conventions. So far I have just been naming each file separately (I am on a... (4 Replies)
Discussion started by: Ralze34
4 Replies

6. Shell Programming and Scripting

How to rename multiple files at one go?

Hi, I have hundreds of files with XXX in their file name and I want to rename all of them with YYY in place of XXX. for ex: $ ls -1 123XXX789 345XXX678 Output $ ls -1 123YYY789 345YYY678 I know we can loop in each file and sed to replace and rename each file but ren *XXX* *YYY*... (4 Replies)
Discussion started by: reddyr
4 Replies

7. UNIX for Dummies Questions & Answers

Is there any way to cat multiple files and show filenames?

Hi, Is there any way to do a cat * where it shows the name of each file in the process? Similar to what more does below? $ more ?.sql :::::::::::::: 1.sql :::::::::::::: set linesize 200 select db_unique_name, cast( from_tz( cast(... (5 Replies)
Discussion started by: newbie_01
5 Replies

8. Shell Programming and Scripting

There are multiple filenames in the directory.How to return the the lastest files for each file name

there are mutiple file nams in the directory. How to return the the lastest files for each file name. ex. abc1234_050201 abc1234_050206 abc1234_050208 xyz34_050204 xyz34_050210 xyz34_050218 thanks (4 Replies)
Discussion started by: grand_sam
4 Replies

9. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

10. Shell Programming and Scripting

Rename multiple files in one go

OS : Oracle Linux 6.8 shell : bash As shown below, I have multiple files like below (query1-extract_aa, query1-extract_ab, query1-extract_ac, ....) $ ls -l total 235680 -rw-rw-r-- 1 reportusr reportusr 30M May 3 11:25 query1-extract_aa -rw-rw-r-- 1 reportusr reportusr 30M May 3 11:25... (5 Replies)
Discussion started by: kraljic
5 Replies
STRSEP(3)						   BSD Library Functions Manual 						 STRSEP(3)

NAME
strsep, stresep -- separate strings LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * strsep(char **stringp, const char *delim); char * stresep(char **stringp, const char *delim, int escape); DESCRIPTION
The strsep() function locates, in the nul-terminated string referenced by *stringp, the first occurrence of any character in the string delim (or the terminating '' character) and replaces it with a ''. The location of the next character after the delimiter character (or NULL, if the end of the string was reached) is stored in *stringp. The original value of *stringp is returned. An ``empty'' field, i.e., one caused by two adjacent delimiter characters, can be detected by comparing the location referenced by the pointer returned by strsep() to ''. If *stringp is initially NULL, strsep() returns NULL. The stresep() function also takes an escape character that allows quoting the delim- iter character so that it can be part of the source string. EXAMPLES
The following uses strsep() to parse a string, containing tokens delimited by white space, into an argument vector: char **ap, *argv[10], *inputstring; for (ap = argv; ap < &argv[9] && (*ap = strsep(&inputstring, " ")) != NULL;) { if (**ap != '') ap++; } HISTORY
The strsep() function is intended as a replacement for the strtok() function. While the strtok() function should be preferred for portabil- ity reasons (it conforms to ANSI X3.159-1989 (``ANSI C89'')) it is unable to handle empty fields, i.e., detect fields delimited by two adja- cent delimiter characters, or to be used for more than a single string at a time. The strsep() function first appeared in 4.4BSD. BSD
August 12, 2006 BSD
All times are GMT -4. The time now is 01:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy