Sponsored Content
Full Discussion: Remove parts from a filename
Top Forums Shell Programming and Scripting Remove parts from a filename Post 302647707 by donadarsh on Monday 28th of May 2012 03:29:16 PM
Old 05-28-2012
see the below code -
Code:
#original File name
filename=tempblast12345A11093.out_

#define pattern 1
pat1=tempblast
#define pattern 2
pat2=11093.out_

#find the length of each pattern including filename
WLEN1=${#pat1}
WLEN2=${#pat2}
FLEN=${#filename}

#calculate the first position to cut
POS1=`expr $WLEN1 + 1`
#calculate the second position to cut
POS2=`expr $FLEN - $WLEN2`

#assign the new filename into new variable and print
NFILE=`echo $filename|cut -c$POS1-$POS2`
echo $NFILE


Last edited by donadarsh; 05-28-2012 at 04:38 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

remove filename prefix

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

A problem for sed? Remove parts of a string

Hi, My knowledge about sed is limited but I have a problem that I think can be solved with sed. I have a variable in a shell script that stores a lot of path/filenames and the delimitter between them is a space (they all exist on the same line). One part of the filename is the file creation... (4 Replies)
Discussion started by: pcrs
4 Replies

3. Shell Programming and Scripting

How to remove numbers from filename

Hi all, Can I edit this script: find . -type f | while read i;do && mv "$i" "${i//abc/}" ;done so that it will not only take out abc from the filename but also take out any numbers that might be in the filename as well. An example would be, Input: filename abc 2009.mov Output:... (7 Replies)
Discussion started by: Monkey Dean
7 Replies

4. Shell Programming and Scripting

how to remove last two extensions of a filename

hi how to remove extensions of a file.. suppose i have a filename "gtk2-2.4.13-24.el4.x86_64.rpm" and i want the file name as "gtk2-2.4.13-24.el4" means want to remove last two "." extensions of a file can anyone help me in this thanks in advance srik (12 Replies)
Discussion started by: srikanthg
12 Replies

5. Shell Programming and Scripting

Using bash to separate files files based on parts of a filename

Hey guys, Sorry for the basic question but I have a lot of files that I want to separate into groups based on filenames which I can then cat together. Eg I have: (a_b_c.txt) WB34_2_SLA8.txt WB34_1_SLA8.txt WB34_1_DB10.txt WB34_2_DB10.txt WB34_1_SLA8.txt WB34_2_SLA8.txt 77_1_SLA8.txt... (1 Reply)
Discussion started by: Breentax
1 Replies

6. Shell Programming and Scripting

How to remove sections of a filename?

Hello, I need some help with renaming some files by removing a certain portion of the filename. The current file name is: ABC_2013186197_20130708_203556.95336 I need to remove the 5 digits after the first "_". The new file name should be: ABC_197_20130708_203556.95336 I'm not quite... (5 Replies)
Discussion started by: bbbngowc
5 Replies

7. Shell Programming and Scripting

Incrementing parts of ten digits number by parts

I have number in file which contains date and serial number: 2013101000. The last two digits are serial number (00). So maximum of serial number is 100. After reaching 100 it becomes 00 with incrementing 10 which is day with max 31. after reaching 31 it becomes 00 and increments 10... (31 Replies)
Discussion started by: Natalie
31 Replies

8. Shell Programming and Scripting

Remove the last 9 characters of a filename

Hi All! Please can someone help, I have a dir with the following files: ~-rw-r--r-- 1 emmuser users 2087361 Oct 16 15:50 MPGGSN02_20131007234519_24291.20131007 -rw-r--r-- 1 emmuser users 2086837 Oct 16 15:50 MPGGSN02_20131007233529_24272.20131007 -rw-r--r-- 1 emmuser ... (7 Replies)
Discussion started by: fretagi
7 Replies

9. Shell Programming and Scripting

Remove spaces in filename

Hi team, Here's a requirement for me. Here are the list of files i have in a unix directory. W 2 A D_2014.csv W 3 A D_2014.csv W 4 A D_2014.csv /home/kmani00-> uname -a AIX sliyyvxx 1 6 00F613E54C00 /home/kmani00-> The file names has to be without spaces as follows. W2AD_2014.csv... (1 Reply)
Discussion started by: kmanivan82
1 Replies

10. Shell Programming and Scripting

How to remove answers and explanation parts from a text file with lots of questions.?

Hi, I have a text file with thousands of questions in it. Each question (multiple lines) with multiple choice options, Answer and Explanation (optional). I need to delete Answer & explanation parts for all Questions and insert a blank line before net question. Each question starts with NO. I... (4 Replies)
Discussion started by: prvnrk
4 Replies
XMLCATALOG(1)							 xmlcatalog Manual						     XMLCATALOG(1)

NAME
xmlcatalog - Command line tool to parse and manipulate XML or SGML catalog files. SYNOPSIS
xmlcatalog [--shell | --create | --add type orig replace | --del values | --noout | --verbose] [catalogfile] [entities] INTRODUCTION
xmlcatalog is a command line application allowing users to monitor and manipulate XML and SGML catalogs. It is included in libxml2. Its functions can be invoked from a single command from the command line, or it can perform multiple functions in interactive mode. It can operate on both XML and SGML files. COMMAND LINE OPTIONS
--shell filename Run a shell allowing interactive queries on catalog file filename. --create filename Create a new XML catalog. Outputs to stdout, ignoring filename unless --noout is used, in which case it creates a new catalog file filename. --add 'type' 'orig' 'replace' filename Add an entry to catalog file filename. type indicates the type of entry. Possible types are 'public', 'system', 'rewriteSystem', 'delegatePublic', 'delegateSystem'amd 'rewriteURI'. 'orig' is the original reference to be replaced, and 'replace' is the URI of the replacement entity to be used. The --add option will not overwrite filename, outputing to stdout, unless --noout is used. The --add will always take three parameters even if some of the XML catalog constructs will have only a single argument. If the --add option is used following the --sgml option, only a single argument, a filename, is used. This is used to add the name of a catalog file to an SGML supercatalog, a file that contains references to other included SGML catalog files. --del 'values' filename Remove entries from the catalog file filename matching 'values'. The --del option will not overwrite filename, outputing to stdout, unless --noout is used. --noout Save output to the named file rather than outputing to stdout. --sgml Uses SGML Super catalogs for --add and --del options -v or --verbose output debugging information. SHELL COMMANDS
Invoking xmlcatalog with the --shell filename option opens a command line shell allowing interactive access to the catalog file identified by filename. Invoking the shell provides a command line prompt after which commands can be entered. public 'PublicID' Execute a public identifier lookup of the catalog entry for 'PublicID'. The corresponding entry will be output to the command line. system 'SystemID' Execute a public identifier lookup of the catalog entry for 'SystemID'. The corresponding entry will be output to the command line. add 'type' 'orig' 'replace' Add an entry to the catalog file. type indicates the type of entry. Possible types are 'public', 'system', 'rewriteSystem', 'dele- gatePublic' and 'delegateSystem'. 'orig' is the original reference to be replaced, and 'replace' is the URI of the replacement entity to be used. del 'values' Remove the catalog entry corresponding to 'values'. dump Print the current catalog. debug Print debugging statements showing the steps xmlcatalog is executing. quiet Stop printing debugging statements. exit Quit the shell. RETURN VALUES
xmlcatalog's return codes provide information that can be used when calling it from scripts. 0: normal 1: Failed to remove an entry from the catalog 2: Failed to save to the catalog, check file permissions 3: Failed to add an entry to the catalog 4: Failed to lookup and entry in the catalog REFERENCES
libxml web page: http://www.xmlsoft.org/ libxml catalog support web page:: http://www.xmlsoft.org/catalog.html James Clark's SGML catalog page:: http://www.jclark.com/sp/catalog.htm OASIS XML catalog specification: : http://www.oasis-open.org/committees/entity/spec.html AUTHOR
John Fleck. XMLCATALOG(1)
All times are GMT -4. The time now is 08:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy