P. Geus P. Geus - 10 months ago 56
Bash Question

Solaris: Regex how to select files with certain filename

First of all, the server runs Solaris.
The context of my question is Informatica PowerCenter.

I need to list files situated in the Inbox directory. Basically, the outcome should be one file list by type of file. The different file types are distinguished by the file name. I don't want to update the script every time a new file type starts to exist so I was thinking of a parameterized shell script with the regex, the inbox directory and the file list

An example:


... has to result in 2 list files containing the path and file name of the listed files:


Answer Source

Assuming all input files follow the convention you indicate (when splitting on dots, the 3rd and 4th column determine the type), this script might do the trick:

#! /usr/bin/env bash

# First parameter or current directory
# Second parameter (or first input directory if not given)
# Filter out directories
INPUTFILES=$(ls -p $INPUTDIR | grep -v "/")

echo "Input: $INPUTDIR, output: $OUTPUTDIR"

  FILETYPE=$(echo $FILE | cut -d. -f3,4)


./script.sh Inbox Inbox/collections

Will read all files (not directories) from Inbox, and write the collection files to Inbox/collections. Filenames inside collections should be sorted alphabetically.