Need to display the output of ls -l selected columns

Hello Friends,

Hope you are doing well.

I am writing a shell script to find out the log file which are not updated in last 1 hours. I've almost completed the script but need your help in formatting its outputs.

Currently, the output of the script is like this(as a flat row):

-rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log

In this the domain name is ICCIR2Test11, log file would be *.log and time would be its modification time as usual.

I need to convert the output as below:

Domain Name Log File Time last updated

ICCIR2Test11 ApplicationManagement.log Jun 18 10:01

I tried the below codes just for a test,

echo -rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log | cut -d"/" -f6; echo -rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log | cut -d" " -f5,6,7

and the output is

ICCIR2Test11
Jun 18 10:01

Can you please let me know if it is possible to convert it into the format described above?

Any help would be highly appereciated.

Thanks,
Chandan

If your directory location is fixed and always same;

try:

your script | awk -F '[ /]' '{print $13,$15,$5,$6,$7}'

If your path may vary, and can go beyond the current directory, please let us know.

Thanks a ton Chanchal!!!!!

The awk statement works perfectly and my currently directory path will always remain the same.

Have a great weekend..

For exa

# cat yourscript
echo "-rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log"
# ./yourscript | ./cutit
Jun 18 10:01 ICCIR2Test11 ApplicationManagement.log
# cat cutit
#!/bin/bash
file=$1
a=0;i=0
for part in `cat $file`
do
((i++))
if [ $i = 5 ] || [ $i = 6 ] || [ $i = 7 ] ; then
tmp[a]=$part
((a++))
fi
if [ $i = 8 ] ; then
domain=$(echo $part | cut -d'/' -f6)
logfile=$(echo $part | cut -d'/' -f8)
fi
done
echo ${tmp[@]} $domain $logfile