Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Rename file based on first 3 characters of data in file Post 302242155 by jchappel on Wednesday 1st of October 2008 09:01:37 AM
Old 10-01-2008
Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file.

An example is:

Read FileA
If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3 positions are "UNB" then rename the file FileA_UNB.

I believe I might be able to use the GREP command to identify the data but not sure how to rename the file being processed.

Appreciate any feedback.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename File Based on Created Date

I am trying to rename files based on the created/born date of the file. I Have a total of 4000 files that i am trying to do this with and would like it to be log_yyyymmddhh.gz right now the files are maillog.???.gz. Can anyone point me in the right direction of how to get this done via scipt? ... (4 Replies)
Discussion started by: Paulb
4 Replies

2. Shell Programming and Scripting

Rename folder based on containing XML file

Hi everyone. I'm in need of a solution where i need to rename a folder to a name that's inside an XML file in that folder. OS is Ubuntu 9.10 with Gnome. I've tried using grep, sed and xpath, but can't seem to find a solution. This is the simplified folder structure: FOLDER-NAME -... (4 Replies)
Discussion started by: CoolCow
4 Replies

3. Shell Programming and Scripting

Need to rename file based on name in same file

Good day. I need a one-liner (if possible) otherwise a longer script to do the following: I have a list of files in a directory with the same filename extension, ie. firstfile.cks, anotherfile.cks, somefile.cks, etc.The filename and extension, however, are incorrect. The correct filename... (7 Replies)
Discussion started by: BRH
7 Replies

4. Shell Programming and Scripting

Rename portion of file based on another file

Hello, I've been searching and reading, but I can't figure out how to solve this problem with my newbie skills. In my directory, I have a list of files (see dirlist.txt attachment) that I need to merge and rename. I have part of the code of the code figured out (see below). However, I... (3 Replies)
Discussion started by: anjulka
3 Replies

5. Shell Programming and Scripting

Rename a file based on a specific separator

Hello, I am new to shell I have a folder which contains a list of files, all the files contain the separator : I need to replace this character for all the filenames (by batch) ex: hello:world should become hello-world please help Thanks (3 Replies)
Discussion started by: sikilaklak
3 Replies

6. Shell Programming and Scripting

Filename rename with characters of file

Hi, I need a bit of help. I've used awk to get the first 7 characters of a file - awk '{print substr($0,0,7)}' test.csv How do I now take this variable to rename test.csv to variable.csv ? Any help or advice would be greatly appreciated! (2 Replies)
Discussion started by: sianm
2 Replies

7. Shell Programming and Scripting

Remove or rename based on contents of file

I am trying to use the two files shown below to either remove or rename contents in one of those files. If in file1.txt $5 matches $5 of file2.txt and the value in $1 of file1.txt is not "No Match" then that value is substituted for all values in $5 and $1 of file2.txt. If however in $1 ... (5 Replies)
Discussion started by: cmccabe
5 Replies

8. Shell Programming and Scripting

Rename files based on name in text file

Hello, I have a text file "file.list" with the contents below. file1 filename1 file2 filename2 file3 filename3 file1, file2 and file3 are files existing in the same directory as the text file file.list. I want to rename file1 to filename1, file2 to filename2, as show in the text... (1 Reply)
Discussion started by: james2009
1 Replies

9. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

10. UNIX for Beginners Questions & Answers

Rename File Name with Special Characters

I am trying to rename files with spaces and other characters and not able to be successful. FileNames: UPLOAD REFERENCE.xls UPLOAD MASS REFERENCE.XLS find /UPLOAD REFERENCE/ -depth -type f -name "* *" -exec rename " " "_" "{}" ";" The above one is successful to replace spaces... (1 Reply)
Discussion started by: eskay
1 Replies
STG-BRANCH(1)							   StGit Manual 						     STG-BRANCH(1)

NAME
stg-branch - Branch operations: switch, list, create, rename, delete, ... SYNOPSIS
stg branch stg branch <branch> stg branch --list stg branch --create <new-branch> [<committish>] stg branch --clone [<new-branch>] stg branch --rename <old-name> <new-name> stg branch --protect [<branch>] stg branch --unprotect [<branch>] stg branch --delete [--force] <branch> stg branch --description=<description> [<branch>] DESCRIPTION
Create, clone, switch between, rename, or delete development branches within a git repository. stg branch Display the name of the current branch. stg branch <branch> Switch to the given branch. OPTIONS
-l, --list List each branch in the current repository, followed by its branch description (if any). The current branch is prefixed with >. Branches that have been initialized for StGit (with linkstg:init[]) are prefixed with s. Protected branches are prefixed with p. -c, --create Create (and switch to) a new branch. The new branch is already initialized as an StGit patch stack, so you do not have to run linkstg:init[] manually. If you give a committish argument, the new branch is based there; otherwise, it is based at the current HEAD. StGit will try to detect the branch off of which the new branch is forked, as well as the remote repository from which that parent branch is taken (if any), so that running linkstg:pull[] will automatically pull new commits from the correct branch. It will warn if it cannot guess the parent branch (e.g. if you do not specify a branch name as committish). --clone Clone the current branch, under the name <new-branch> if specified, or using the current branch's name plus a timestamp. The description of the new branch is set to tell it is a clone of the current branch. The parent information of the new branch is copied from the current branch. -r, --rename Rename an existing branch. -p, --protect Prevent StGit from modifying a branch -- either the current one, or one named on the command line. -u, --unprotect Allow StGit to modify a branch -- either the current one, or one named on the command line. This undoes the effect of an earlier stg branch --protect command. --delete Delete the named branch. If there are any patches left in the branch, StGit will refuse to delete it unless you give the --force flag. A protected branch cannot be deleted; it must be unprotected first (see --unprotect above). If you delete the current branch, you are switched to the "master" branch, if it exists. -d DESCRIPTION, --description DESCRIPTION Set the branch description. --force Force a delete when the series is not empty. STGIT
Part of the StGit suite - see linkman:stg[1] StGit 03/13/2012 STG-BRANCH(1)
All times are GMT -4. The time now is 09:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy