ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Renaming an IFS file with Qshell - replacing embedded blanks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Renaming an IFS file with Qshell - replacing embedded blanks

    Hi Folks

    I would like to know how to use Qshell to tidy up file names of files coming into the IFS from outside.

    I have searched extensively for info on MV and SED but the few pages I found were either for renaming every file in a directory (I want to do just one at a time) or they were some other flavour of shell that works differently or has different switches/flags.

    The main application would be removing embedded blanks in file names (e.g. replacing them with underscores or just pushing the words together). Ideally I'd like to be able to replace any number of consecutive blanks with one replacement character, e.g. (with : standing for blank) "A:very:slapdash:::file:name.csv" with "A_very_slapdash_file_name.csv", but code for one-for-one replacement would still be very useful.

    There might be cases too where I want to shorten a name so if you also know a truncation technique that respects word boundaries that would be a bonus (e.g. make the name no more than 30 characters but without splitting a word ... or ... from position 25 find the next blank and truncate there).
    Last edited by WilliamTasker; June 4, 2018, 03:46 PM. Reason: editor removed my deliberate multiple blanks in example.

  • #2
    This is an unusual request. Why are you naming the files like this if you don't want them named like this? You mention that the files are "coming from outside" -- do you really let just anyone create files with any name they like? And, if you've made the business decision to do that, then why not process them with the names assigned? Why do you have to change them?

    You can do the things you're wanting to do, of course... but not sure a QShell script is the best way. It might be better/easier to write a program considering how complex your requirements are.

    Comment

    Working...
    X