01-25-2006
Remove prefix from filenames
I'm trying to put together a shell script that will append specific prefixes based on the content of filenames. I think I have this part down. However, I want to append before that part a process that will remove the current prefix before it renames the files with the new prefix.
For example, if all the files I want to rename, for example are:
---
ALPHANUM.ABCDEFG
ALPHANUM.HIJKLMNOP
ALPHANUM.QRSTUV
ALPHANUM.WXYZ
ALPHANUM.01234567890
---
and depending on the contents, if $[0-9] append the prefix "NUM." and $[A-Z] append prefix "ALPHA". The part where I'm stuck at is trying to figure out how to remove the "ALPHANUM." prefix before I do any appending.
Tried searching through the forums with "remove suffix, change suffix, remove prefix, change prefix," and "prefix" to get some examples, but did not spot anything I'm trying to do.
Please help.
Thanks!
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I've got a bunch of files called oldabc, olddef etc.
i want to copy these to be abc, def....
I can do this with file extensions....but can get the logic to work for prefixes. All the files I am interested in have a prefix of 'old'.
This loop is no good for me....it looks at the content... (2 Replies)
Discussion started by: peter.herlihy
2 Replies
2. Shell Programming and Scripting
Remove prefix using awk
File:
nawk -F"|" '{if ($1 ~ /^xyz./) print; else { gsub(.*\..*, \..*, $1) ;print }}' file
Error:
ouput required: (5 Replies)
Discussion started by: pinnacle
5 Replies
3. Shell Programming and Scripting
Hello Gurus,
O/S RHEL4
I have a requirement to compare two linux based directories for duplicate filenames and remove them. These directories are close to 2 TB each. I have tried running a:
Prompt>diff -r data1/ data2/
I have tried this as well:
jason@jason-desktop:~$ cat script.sh ... (7 Replies)
Discussion started by: jaysunn
7 Replies
4. Shell Programming and Scripting
Hi,
I'm using a .ksh script to split one file into multible files by checking for the prefix per line. It works perfekt (thanks again for anyone involved in helping me with that ;)), but I want to remove the prefix per line too. Means only the line information itself should remain in the... (7 Replies)
Discussion started by: spidermike
7 Replies
5. Shell Programming and Scripting
hi all,
I want to remove filenames beginning with multiple dots.how I can do this.
Thanks in advance (5 Replies)
Discussion started by: sriharsharavi
5 Replies
6. UNIX for Dummies Questions & Answers
I have a group of files in different directories with characters such as " ? : in the file names. How do I find these files and remove these characters on mass?
Thanks (19 Replies)
Discussion started by: barrydocks
19 Replies
7. Shell Programming and Scripting
Hi,
I have files like below, In files coming as spaces. Before transfering those files into ftp server. I want to remove the spaces and then can transfer the files into unix server.
e.g: filenames are
1) SHmail _profile001_20120908.txt
2) SHmail_profile001 _20120908.txt
3) sh... (3 Replies)
Discussion started by: kirankumar
3 Replies
8. Shell Programming and Scripting
Dear all,
I have a dir structure like
main_dir
At_nn Ag_js Nf_hc ....
mcd32 mgd43... mcd32 mgd43... mcd32 mgd43...
and each subdir (e.g. mcd32, mgd43) contains files.
Now, i... (15 Replies)
Discussion started by: yogeshkumkar
15 Replies
9. Shell Programming and Scripting
hi,
i have a directory which contains some files and a subdirectory. i am writing only the files names to a file using the below code.
ls -ltr | grep "^-" | awk '{print $NF}' > /home/file_list$$
cat /home/file_list$$
s1_abc.txt
s2_def.xls
s3_def.xls
as you can see there is one .txt... (7 Replies)
Discussion started by: Little
7 Replies
10. Shell Programming and Scripting
Dear All,
assume i have a file with content:
<Start>6000</Start>
<Stop>7599</Stop>
the output is:
6000
7000
7100
7200
7300
7400
7599
how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix.
Thanks
Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies
LEARN ABOUT DEBIAN
gather_stx_titles
gather_stx_titles(1) General Commands Manual gather_stx_titles(1)
NAME
gather_stx_titles - gather title declarations from Stx documents
SYNOPSIS
gather_stx_titles [ -f from-suffix ] [ -t to-suffix ] [ m4 options ] file [ file ... ]
DESCRIPTION
gather_stx_titles digs out Stx metadata declarations from the listed files, and dumps the title and document ID information as m4 defini-
tions into standard output. This information can later be used by w_crosslink to link the documents by their metadata.
Why is this useful? Well, imagine that you have a large site with a lot of cross-linking. A document's name will appear in many places:
in the link menu (if you have one), and in the body of different pages where it is cross-linked from. gather_stx_titles lets you put all
the information in one place and where it belongs, i.e. the file itself. You'll be glad if you did, when the time comes to change document
titles or move the documents around; especially so if your website has multilingual magic.
OPTIONS
gather_stx_titles uses m4 internally and will accept any option m4 accepts. In addition to those, it takes the following options:
-f from-suffix
In the filename data, substitute away the suffix from-suffix. Actually, from_suffix may be a regular expression; stupid but
true, in GNU m4 it is a "traditional" regexp, whereas in BSD m4 it is an "extended" regexp. Default to no suffix (nothing to
take away).
-t to-suffix
In the filename data, substitute the suffix taken away by from-suffix with to-suffix. If from-suffix is nil (the default),
append to-suffix to all filenames.
-p prefix
Strip away the prefix given by (regular expression) prefix from filenames. The equivalent of -t for this does not exist, because
you can specify a directory prefix to w_crosslink by w_base.
--version, -V
Just show version information and exit.
--help, -?
Just show a short help message and exit.
EXAMPLES
I guess most of the time you will want to automate the use of gather_stx_titles, for example with a Makefile like this:
SOURCES = $(wildcard *.stx)
TARGETS = $(SOURCES:.stx=.html)
all: $(TARGETS)
titles.m4: $(SOURCES)
gather_stx_titles -f stx -t html $^ > $@
%.html: %.stx titles.m4
stx2any -T html titles.m4 $< > $@
If you don't want to be quite so correct, drop the .html dependency on titles.m4 or titles.m4 dependency on SOURCES. Using temporary files
is not necessary: this should also work:
$ gather_stx_titles *.stx | stx2any - mydoc.stx
SEE ALSO
stx2any (1).
AUTHOR
This page is written by Panu A. Kalliokoski.
Panu A. Kalliokoski gather_stx_titles(1)