Sponsored Content
Top Forums Shell Programming and Scripting How can I extract digits at the end of a string in UNIX shell scripting? Post 303026263 by mingch on Thursday 22nd of November 2018 10:20:32 PM
Old 11-22-2018
I tried to create the following scripts but it can't increment the last number from 012 to 013, anyone help? Many thanks.

Code:
#!/bin/sh
cat file.txt | while read FN
  do
    FNPATH=${FN%/*}
    FNFILE=${FN##*/}
    BNFILE=`echo "${FNFILE%.txt}" | sed "s/[0-9]\{1,10\}$//"`
    OLDNUM=`echo "${FNFILE%.txt}" | sed 's/.*[^0-9]\([0-9][0-9]*\)/\1/'`
    NEWNUM=$(($OLDNUM+1))
    NEWFILE="${BNFILE}${NEWNUM}.txt"
   echo "OLD file is ${FN}, NEW file is $FNPATH/${NEWFILE}"
  done

Output
Code:
OLD file is /tmp/path1/abc_d123_4567.txt, NEW file is /tmp/path1/abc_d123_4568.txt
OLD file is /tmp/path2/A246_B789.txt, NEW file is /tmp/path2/A246_B790.txt
OLD file is /tmp/path12/B123cc099.txt, NEW file is /tmp/path12/B123cc100.txt
OLD file is /tmp/path12/a123_B234-012.txt, NEW file is /tmp/path12/a123_B234-13.txt
OLD file is /tmp/path13/a13.txt, NEW file is /tmp/path13/a14.txt
OLD file is /tmp/path13/1.txt, NEW file is /tmp/path13/2.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract digits at end of string

I have a string like xxxxxx44. What's the best way to extract the digits (one or more) in a ksh script? Thanks (6 Replies)
Discussion started by: offirc
6 Replies

2. Shell Programming and Scripting

Need UNIX shell scripting end to end information

Hi, I would like to learn shell scripting in UNIX. Can any one please give me the support and share the information/documents with me. If any documents please post it to aswanikumar_nimmagadda@yahoo.co.in Thanks in advance...!!! (3 Replies)
Discussion started by: aswani_n
3 Replies

3. Shell Programming and Scripting

Search and remove digits (if exist) from end of the string

Hi Experts, Here is what I am trying to do. 1) say I have a file with below strings database1 database2 database3 data10gdb1 data10gdb2 databasewithoutdigit 2) I want to get the below output. (- if there is any digit at the end of the string, I need to remove it) (- Any... (3 Replies)
Discussion started by: shail_boy
3 Replies

4. Shell Programming and Scripting

extract digits from a string in unix

Hi all, i have such string stored in a variable var1 = 00000120 i want the o/p var1 = 120 is it possible to have such o/p in ksh/bash ... thanx in advance for the help sonu (3 Replies)
Discussion started by: sonu_pal
3 Replies

5. Shell Programming and Scripting

help with Scripting - trying to search for string and extract next few characters

Hi I am new to world on unix scripting so any assistance would be gratefully appreciated, I am trying to write a script which reads through a file, reads in line by line, searches for a pattern, copies string after it and then to do a search and replace elsehwere in the line, so the... (7 Replies)
Discussion started by: LonJ_80
7 Replies

6. Shell Programming and Scripting

BASH: remove digits from end of string

Hi there, im sure this is really simple but i have some strings like this e1000g123001 e1000g0 nge11101 nge3and i want to create two variables ($DRIVER and $INSTANCE). the first one containing the alpha characters that make up the first part of the string, e.g. e1000g or nge and the... (9 Replies)
Discussion started by: rethink
9 Replies

7. Shell Programming and Scripting

How to add trailer record at the end of the flat file in the unix ksh shell scripting?

Hi, How to add trailer record at the end of the flat file in the unix ksh shell scripting can you please let me know the procedure Regards Srikanth (3 Replies)
Discussion started by: srikanth_sagi
3 Replies

8. Shell Programming and Scripting

How to extract text from STRING to end of line?

Hi I have a very large data file with several hundred columns and millions of lines. The important data is in the last set of columns with variable numbers of tab delimited fields in front of it on each line. Im currently trying sed to get the data out - I want anything beetween :RES and... (4 Replies)
Discussion started by: Manchesterpaul
4 Replies

9. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

10. Shell Programming and Scripting

Extract n-digits from string in perl

Hello, I have a log file with logs such as 01/05/2017 10:23:41 : file.log.38: database error, MODE=SINGLE, LEVEL=critical, STATE: 01170255 (mode main how can i use perl to extract the 8-digit number below from the string 01170255 Thanks (7 Replies)
Discussion started by: james2009
7 Replies
PROFTMB(1)							   User Commands							PROFTMB(1)

NAME
proftmb - per-residue prediction of bacterial transmembrane beta barrels SYNOPSIS
proftmb [options] DESCRIPTION
proftmb predicts bacterial transmembrane beta barrels from sequence using profile fed Hidden Markov Models (HMM). Output format Self-annotating. Letters of prediction: 'i' - inside cytoplasm, 'O' - outside cytoplasm, 'U' - up (on chain moving out of cytoplasm), 'D' - down (on chain moving into cytoplasm). References Bigelow, H. and Rost, B. (2006). PROFtmb: a web server for predicting bacterial transmembrane beta barrel proteins. Nucleic Acids Res, 34(Web Server issue), W186-8. To invoke the menu, type: proftmb --menu The options are: -d, --directory-root <STRING> root path where files (options -s,-r,-l,-a,-e,-t,-u,-z,-n) reside -a, --reduction-state-decode <STRING> state reduction for decoding -b, --reduction-state-report <STRING> state reduction for reporting -m, --membrane-strand-states <STRING> list of membrane strand states -z, --z-curve-file <STRING> file containing means and sd's at integral length values -x, --z-calibration-curve <STRING> file mapping coverage and accuracy values to z-scores -n, --null-frequency <STRING> background frequency file -c, --minimum-score-cutoff <DOUBLE> minimum z-score for per-residue prediction -o, --outfile-prefix <STRING> output file prefix for the three files generated: PREFIX_dat.txt, PREFIX_proftmb_pretty.txt PREFIX_proftmb_tabular.txt -s, --static-model-data <STRING> data representing the model architecture -t, --trained-params <STRING> params representing the encoded training data -q, --test-blastQ-file-or-dir <STRING> psiblast profile (-Q) or directory (full pathname or relative to current directory) with many profiles -w, --single-sequence-name <STRING> if -q option points to a single file, this is the name -v, --list-blastQ-files <STRING> list of psiblast files to process in directory (leave blank to process all files) --outfile-pretty <STRING> pretty output file (overrides automatic name PREFIX_proftmb_pretty.txt) --outfile-tab <STRING> tabulated output file (overrides automatic name PREFIX_proftmb_tabular.txt) --outfile-dat <STRING> data output file (overrides automatic name PREFIX_dat.txt) --version <BOOL> output version information and exit --quiet <BOOL> be quiet EXAMPLES
proftmb @/usr/share/proftmb/options -q /usr/share/doc/proftmb/examples/example.Q -o /tmp/example The above produces 3 output files: /tmp/example_proftmb_tabular.txt, /tmp/example_proftmb_pretty.txt and /tmp/example_dat.txt. Compare these to the examples in /usr/share/doc/proftmb/examples. BUGS
Please report bugs at <https://rostlab.org/bugzilla3/enter_bug.cgi?product=proftmb>. COPYRIGHT
Copyright (C) 2004 Henry Bigelow This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. proftmb 1.1.10 February 2012 PROFTMB(1)
All times are GMT -4. The time now is 09:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy