Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strip time stamp from file name

Status
Not open for further replies.

bankshot6164

Programmer
Feb 6, 2007
2
US
What is the syntax to strip a timestamp from the end of a file name to process through a Unix job script. I am a newbe to UNIX and would appreciate anyones help.
Thanks,
Bankshot
 
man expr

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
can you give an example of what the file name looks like?
 
Hi sbrews,
the input file would be similar to the one below:
CECOLL_AGCY_InputtoDEP_RINTJ750_200702070567436
I would like to able to wild card to the time stamp.
This is the code I have that's NOT working!!! File not Found

case $PARAM1 in
"OC1") FILE=CECOLL_AGCY_InputToDEP_RINTJ617*;;

export ITAS_INTRF_FILE1=$ITAS_INTRF/$FILE
export FILENAME=$FILE

files='ls -lt $ITAS_INTRF|grep
$ITAS_INTRF_FILE1|awk '{print $9}

if [-Z $ITAS_INTRF_FILE1]; then
echo "$EXEC: File $ITAS_INTRF_FILE1 does not exist"
exit $FAILURE
fi
 
This should do what you want:

Code:
case $PARAM1 in 
      "OC1") FILE=`echo CECOLL_AGCY_InputtoDEP_RINTJ750*`;;

# ...
#  Assuming there is more case statments and a esac
#  to close/finish the case statement
# ...

export ITAS_INTRF_FILE1=$ITAS_INTRF/$FILE
export FILENAME=$FILE

# I am assuming that the ITAS_INTRF above is defined elsewhere in your script.
# Also assuming the FILENAME will be used elsewhere in the script.

files=`ls -lt $ITAS_INTRF|grep $FILE|awk '{print $9}'`

#I am assuming the "files=..." line and the one right after 
#it should be one line.  Note the ticks [b]'[/b] and the 
#back ticks [b]`[/b].  The line as originally specified 
#would not work - this new version will - not sure what you 
#are doing with this as its not referenced the code fragment
#- other than assigning a value to it.


if [ -z $ITAS_INTRF_FILE1 ]
then
    echo "$EXEC:  File $ITAS_INTRF_FILE1 does not exist"
    exit $FAILURE
fi

#on the [b]if [-Z $INTAS_INTRF_FILE1][/b], the [b]-Z[/b] 
#needs to be lower case: [b]-z[/b] and whitespace is needed 
#after the [ and before the ].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top