Tag Archives: FILEN

awk for a string in a filename

By jimbojames

Hi there

I have the variable command below in a script to list the file name in a directory:

Code:

FILEN="$(ls | awk '{print $1}')"


.
When it is run, it correctly returns the following:

Quote:

MYFILE_NAME_20130221000026.CSV


. I would like to be able to cut the date/time portion of the filename and store it as a variable for later use, is it possible to do this, and what is the best method to achieve it?

Thank you

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Redirect Standard Error to /dev/null is not working.

By jimbojames

Hello.

When I run a .ksh that contains the command below, and there is no file available in the source location the “FILE_NAME_*.CSV not found” error is still being displayed.

Code:

FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}") 2> /dev/null


.

This is interfering with the rest of the script, as it is not exiting as required, and is continuing to the next command (See below).

Code:

echo "- Listing available file(s) on ${SOURCE_SERV}${SOURCE_LOCATION}:n"
FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}") 2> /dev/null
print ${FILEN}
if [ $? -eq 0 ]; then
echo "n- End of Source of files list."
else
echo "tt#####################################ntt# NO FILES AVAILABLE. #ntt#####################################nnn- Exiting script"
exit 0
fi


Can anyone advise what I am doing wrong with the redirection? Basically If there are no files available, I need to echo the warning and exit the script successfully.

Thanks in advance.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums