• FidoGazette Vol 13 no 26 Page: 2

    From Janis Kracht@1:261/38 to All on Wed Jun 26 23:09:20 2019
    ================================================================
    A R T I C L E S
    ================================================================



    One of the first scripts I wrote under Linux quite a while back
    was this one.. I needed something to automatically rename all
    the "/home/bbbs/inbound/*.bad" files to "*.tic" after a
    near-bbs-death-event..

    ========Script: mvbad2tic==========
    #!/bin/sh
    list="`ls -1 *.bad`"
    for file in $list
    do
    f=`basename $file .bad`.tic
    mv $file $f
    done
    ===================================

    basename prints file name NAME with any leading directory
    components removed. Optionally, it can also remove any trailing
    suffix.





    FIDOGAZETTE Vol 13 No 26 Page 2 June 26, 2019


    -----------------------------------------------------------------

    --- BBBS/Li6 v4.10 Toy-4
    * Origin: Prism bbs (1:261/38)
  • From mark lewis@1:3634/12.73 to Janis Kracht on Thu Jun 27 00:00:30 2019
    On 2019 Jun 26 23:09:20, you wrote to All:

    ========Script: mvbad2tic==========
    #!/bin/sh
    list="`ls -1 *.bad`"
    for file in $list
    do
    f=`basename $file .bad`.tic
    mv $file $f
    done
    ===================================

    that's pretty neat! another way it could be done is this oneliner...

    ls -1 *.bad | \
    tr '\n' '\0' | \
    xargs -0 -n 1 -i basename "{}" .bad | \
    tr '\n' '\0' | \
    xargs -0 -n 1 -i echo mv "{}".bad "{}".tic

    it seems convoluted but actually makes sense once you figure it out... plus it handles files with spaces in their names...

    1. list the *.bad files one per line
    2. replace newlines with nuls
    3. use xargs to feed each line to basename to strip leading path and trailing .bad
    4. replace newlines with nuls
    5. use xargs to feed each line to mv (remove echo when you see it print the commands as you expect)

    we've been using this following one with various changes depending on the extensions needed... it uses sed recipe for the change of extension and handles
    files with spaces, too... you just have install rename...

    rename 's/\.bad$/.pkt/' *.bad

    it was very handy when first setting up the new system and traffic was already flowing while we were still configuring the tosser which was renaming a lot of pkts to bad because we were still looking up and configuring the packet passwords :lol:

    )\/(ark

    Always Mount a Scratch Monkey
    Do you manage your own servers? If you are not running an IDS/IPS yer doin' it wrong...
    ... "Who stole my thermal underwear?" the hunter asked coldly.
    ---
    * Origin: (1:3634/12.73)