Versioning up a file with initials?

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
Versioning up a file with initials?

I have this code that works great ...


for file in "$@"
        num=${num#$zeroes}      #remove leading zeros, or it uses octal
        new=$(printf '%sv%04d.%s' "$base" "$num" "$ext")
        cp -nv "$file" "$new"

Now I need it to work with a file that has two characters after the version number.

I've tried just about everything I know to get this to work but it seems the characters get picked up as part of the number.

Any help is appreciated.

Thank you.
# 2  
You could try adding these intermediate steps after num=${base##*v} to remove trailing characters after the last digit (what you call "initials"):

Last edited by Scrutinizer; 05-18-2019 at 12:31 AM..
# 3  
That works but I lose the "initials."
The file produced is 098_FGT_550_comp_v0003.nk

Once I get this working, several different people will be using it, so I need it to restore the initials.
# 4  
Not sure where the problem is:
printf '%sv%04d%s.%s' "$base" "$num" "$initials" "$ext"

Your three digit version number has become four digit with your printf format.

Or, why not (provided you have a recent bash or ksh)

ARR=( $file )
echo cp "$file" "$(printf '%sv%04d%s.%s\n' "${ARR[0]}" "$((10#${ARR[1]%%[^0-9]*} + 1))" "${ARR[1]##*[0-9]}" ${ARR[-1]})"
cp 098_FGT_550_comp_v002gp.nk 098_FGT_550_comp_v0003gp.nk

Last edited by RudiC; 05-18-2019 at 06:57 AM..
# 5  
Originally Posted by scribling
That works but I lose the "initials."
The file produced is 098_FGT_550_comp_v0003.nk

Once I get this working, several different people will be using it, so I need it to restore the initials.
With the intermediate steps I suggested, the "initials" are saved in the initials variable, so you can use them wherever you please.
So try:
new=$(printf '%sv%04d%s.%s' "$base" "$num" "$initials" "$ext")

If they need to go somewhere else, then please specify the end result.

Last edited by Scrutinizer; 05-18-2019 at 07:59 AM..
# 6  
That works great!
Thank you.

It seems to easy now that I see it done correctly.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #175
Difficulty: Medium
ENIAC was one of the first electronic computers and occupied 167 square meters, weighed 27 tons and consumed 150kW of electricity.
True or False?

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to get versioning of the branch name dynamically

Hi, I need to get versioning of the branch name dynamically. can you please help us to achieve this functionality. curl curl everytime... (5 Replies)
Discussion started by: lkeswar
5 Replies

2. UNIX for Dummies Questions & Answers

Find a file with common initials and last words

Hi, I have a requirement like i have to find out files and remove them on a daily basis. The files are generated as abc_jnfn_201404230004.csv abc_jnfo_201404230004.csv abc_jnfp_201404230004.csv abc_jnfq_201404230004.csv abd_jnfn_201404220004.csv abe_jnfn_201404220004.csv i want to... (1 Reply)
Discussion started by: Mohammed_Tabish
1 Replies

3. SCO

Versioning through undelete

Hi , I am using SCO openserver realease 3.2 and tried to test versioning on a directory with undelete -s . The command executes well but it is not creating any versions of the files in it. I have also setted versioning options via filesystem and then remounted it but of ... (0 Replies)
Discussion started by: dextergenious
0 Replies

4. Shell Programming and Scripting

Initials of a name

I'm stuck, so please tell me how to print the initials of a name (for ex E C for Eric Cartman). If you could suggest a website related to string handling then that would be much appreciated too. Thanks! (3 Replies)
Discussion started by: deepwoodsv
3 Replies

5. Shell Programming and Scripting

File Versioning with Shell Script

Need to add the version date to the moved file if same file name in folder exists and limit the same files in the folder. Ex: If moved or copy file abc.txt to folder XYZ then append the version date abc07112011.txt or abc07122011.txt in the folder. \xyz abc07132011.txt abc07122011.txt... (2 Replies)
Discussion started by: Brado
2 Replies

6. Linux

Any Filesystems in Linux Support Versioning?

A question that has come up repeatedly where I work from our former VMS guys is... "will any Linux filesystem ever support versioning like RMS did"? When they talk about versioning they really are talking about something that *I think* would involve having apps that support versioning. For... (7 Replies)
Discussion started by: deckard
7 Replies

7. Programming

binary versioning

Dear Members, Do you know any information about versioning a binary file. That means test.out 1.0.0, 1.0.1, 1.1.0, and so on. Can I manually edit version number (both major and minor) and revision number myself (how?) or any utility to set version number (which one?). Best Regards, Francesco (2 Replies)
Discussion started by: francescoandrio
2 Replies

8. Solaris

Solaris versioning

Please correct me if I am wrong... Isnt the only difference between minor releases of Solaris, ex. 9/04 and 9/05, is the patche revs between them? If so, why does the /etc/release info stay static when patched? (4 Replies)
Discussion started by: mhm4
4 Replies

Featured Tech Videos