Sponsored Content
Full Discussion: Help with file rename script
Top Forums Shell Programming and Scripting Help with file rename script Post 302906557 by wisecracker on Friday 20th of June 2014 03:43:22 PM
Old 06-20-2014
Longhand from the CLI only, OSX 10.7.5, default bash terminal...
This makes assumptions that the first field is constant length.
If not then a slightly more difficult approach is needed...
Code:
Last login: Fri Jun 20 18:11:46 on console
AMIGA:barrywalker~> echo 'M16540035421004411262012N 11        SAMPLE WORD SAMPLE WORD' > /tmp/sample
AMIGA:barrywalker~> cat < /tmp/sample
M16540035421004411262012N 11        SAMPLE WORD SAMPLE WORD
AMIGA:barrywalker~> text=$(cat < /tmp/sample)
AMIGA:barrywalker~> echo "$text"
M16540035421004411262012N 11        SAMPLE WORD SAMPLE WORD
AMIGA:barrywalker~> text="${text:20:4}${text:16:4}"
AMIGA:barrywalker~> echo "$text"
20121126
AMIGA:barrywalker~> # REMEMBER TO BACKUP YOUR ORIGINAL FILE.
AMIGA:barrywalker~> mv /tmp/sample /tmp/"Fixed description-Fixed numeric code-$text.txt"
AMIGA:barrywalker~> ls -l /tmp/
total 24
-rw-r-----  1 root         _lp    1193 20 Jun 18:11 0001653a4f82c
-rw-r-----  1 root         _lp    1234 20 Jun 18:11 0001653a7018c
-rw-r--r--  1 barrywalker  wheel    60 20 Jun 20:29 Fixed description-Fixed numeric code-20121126.txt
drwx------  3 barrywalker  wheel   102 20 Jun 18:11 launch-B5kUmu
drwx------  3 barrywalker  wheel   102 20 Jun 18:11 launch-UEgXYb
drwx------  3 barrywalker  wheel   102 20 Jun 18:11 launch-ce6iKr
drwx------  3 barrywalker  wheel   102 20 Jun 18:11 launch-gfvxa4
drwx------  3 barrywalker  wheel   102 20 Jun 18:11 launchd-130.7TVN3n
AMIGA:barrywalker~> cat < /tmp/'Fixed description-Fixed numeric code-20121126.txt'
M16540035421004411262012N 11        SAMPLE WORD SAMPLE WORD
AMIGA:barrywalker~> _

EDIT:
Forgot about the file locking bit, research:-
Code:
man fuser


Last edited by wisecracker; 06-20-2014 at 04:51 PM..
 

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

DOS script to grab the first file in a dir and rename it

:confused: Hello, Is there any way to use the dir command / some DOS Script to select only first file of similar pattern of files in a direcotory and rename it for example, one directory has 5 files abc_1005.txt abc_5256.txt abc_2001.txt abc_2003.txt abc_3006.txt by use script I would... (2 Replies)
Discussion started by: raghav525
2 Replies

2. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

3. UNIX for Advanced & Expert Users

Rename a file to a file_current datetime in a shell script

Hi all, Could anyone suggest me on Renaming a file to a file_current datetime in a shell script. (3 Replies)
Discussion started by: Nithin
3 Replies

4. Shell Programming and Scripting

Script to rename zip-files with name of file

Hi, I'm desperately in search for a solution of the following problem: I have a directory full of zip-files. All these zip-files contain a single file with a name that should be used for the name of the zip-container. Anybody a good idea. I'm an absolute beginner in shell scripting - so please... (7 Replies)
Discussion started by: mark_a17
7 Replies

5. Shell Programming and Scripting

Perl script to rename file,error

#!/usr/bin/perl $FL="ch.txt"; $CFL="mytext.txt"; print "This script will rename textfiles."; mv $FL $CFL; print "Done."; perl file.pl Error: Can't locate object method "mv" via package "ch.txt" (perhaps you forgot to load "ch.txt"?) at file.pl line 7. (5 Replies)
Discussion started by: cola
5 Replies

6. Shell Programming and Scripting

write shell script to rename file

hi, I need some help in writing shell script in a bourne shell.I am trying to rename the file.. eg. find /root/data -type f -name "text*) | while read FILES do newfile=${FILES/type_2.0_20101208_34.xml / tmp.xml} mv "$FILES" "$newfile" done above written script is working...If the... (7 Replies)
Discussion started by: shubhig15
7 Replies

7. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

8. Shell Programming and Scripting

Batch Script To Unzip and Rename File

Hello All, I need help in writing a batch script. I have 100 zip files in a folder. Each zip file has a unique name starting with XYZ_12345.zip Each zip file contains single csv file I would like to batch extract the files and also rename the extracted csv as per the original zip name... (6 Replies)
Discussion started by: rajlakshmi
6 Replies

9. Shell Programming and Scripting

Command / script to partially rename file

Hi I have numerous files names product_host_result_B1000842.txt product_host_result_B1000847.txt product_host_result_C1000842.txt product_host_result_C1000848.txt etc. I need them renamed so that the 'product_host_result' becomes 'output_product_host' but the rest of the filename is... (6 Replies)
Discussion started by: Grueben
6 Replies

10. Shell Programming and Scripting

Help required with a file rename shell script

Hello everyone, Posting here after a long time, been away from unix world lately and it seems I have forgotten my shell scripting completely. I have a requirement where a csv file contains following columns: Full Registration VIN Stock... (14 Replies)
Discussion started by: tayyabq8
14 Replies
ID3TOOL(1)						      General Commands Manual							ID3TOOL(1)

NAME
id3tool - a command line editor for id3 tags. SYNOPSIS
id3tool [options] files ... DESCRIPTION
This manual page is for the id3tool command. id3tool is a program that can be used to view and edit id3 tags from the command line. When invoked from the command line with filenames and no options, it will display the used fields of the id3 tags. When invoked from the command line with filenames and "set" options, it will change the id3 tag fields specified to the specified values on all the files. Due to limitations in the ID3v1 specification, most fields are limited to 30 characters. The note field is limited to 28 characters if a track number is in use. You can force a tag to be v1.1 by using a specifying a non-zero track number, or force a tag to be v1.0 by specifying a track number of zero (0). OPTIONS
The programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A complete list of options are included below. For a complete description, use the help option. -t, --set-title=WORD Sets the title to WORD -a, --set-album=WORD Sets the album to WORD -r, --set-artist=WORD Sets the artist to WORD -y, --set-year=YEAR Sets the year to YEAR [4 digits] -n, --set-note=WORD Sets the note to WORD -g, --set-genre=INT Sets the genre code to INT (the codes can be acquired from the genre list.) -G, --set-genre-word=WORD Sets the genre to WORD (given that WORD is from the genre list.) -c, --set-track=INT Sets the track to INT -h, --help Show summary of options. -v, --version Show version of program. -l, --genre-list Shows the genre list. AUTHOR
id3tool and this manual page were written by Chris Collins <xfire@xware.cx> ID3TOOL(1)
All times are GMT -4. The time now is 03:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy