1834302 Members
2262 Online
110066 Solutions
New Discussion

Re: Extract date also

 
SOLVED
Go to solution

Extract date also

Greetings,

Thanks again for all the help with the du command. I'm now trying to find a way to pull out the date attached to each file. Can this be tacked on to this 'du -akx | sort -rn | sort -k 2,2 | more > file.lst'?
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: Extract date also

Conrad,

The du command does nothing with dates - you could do something like this, however:

for FILE in `cat file.lst`
do
ll $FILE | awk '{ print $6 " " $7 " " $8 " " }'
done


Pete

Pete
Steven E. Protter
Exalted Contributor

Re: Extract date also

Yes, take out the more pipe it to awk

| awk '{print $3}'

change the $3 to include the date fields.

Or process to a file and then cat the file through awk.

There are a few good ways to do this.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Peter Godron
Honored Contributor

Re: Extract date also

Conrad,
can you please clarify:
du does not include the date at any stage.

Or
Do you mean include the date in the filename:
du -akx | sort -rn | sort -k 2,2 | more > `date +"%C%Y%m%d"`.lis
See man date for format

Or
If you want to see the date for each entry in your file you would have to use ls -ld

Re: Extract date also

I guess I wasn't clear enough on this. The current output file does not have the date field in it. I would like to have it in the output file. Currently I get something like this;
143600 ./scans/MCI. I would like to get this along with the date.

Thanks,
Conrad
James R. Ferguson
Acclaimed Contributor

Re: Extract date also

Hi Conrad:

Well, you could do something crude like this:

# du -axk | sort -k1nr | perl -lanF -e ';print "$F[0]\t$F[1] : ",scalar localtime ((stat($F[1]))[9])'

Regards!

...JRF...

Re: Extract date also

Thanks James,

It works, sort of. I can't run it as root but I can live with that I guess. I also modified it back to sort the way it was before I just wanted to include the date tag.

du -akx | sort -rn | sort -k 2,2 | perl -lanF -e ';print "$F[0]\t$F[1] : ",scalar localtime ((stat($F[1]))[9])' > outfile.lst

It seems that when I try and run it as root, root can't find perl. I get 'sh: perl: not found.'

Thanks for all the help,
Conrad
Peter Godron
Honored Contributor

Re: Extract date also

Conrad,
probably means the perl executable in not in your PATH.
Once you found perl, just add it to your path:
export PATH=$PATH:

Re: Extract date also

Thanks gordon,

It runs now if I switch to su - but it still does not work if I switch to su.

Cheers,
Conrad
James R. Ferguson
Acclaimed Contributor
Solution

Re: Extract date also

Hi (again) Conrad:

The difference between 'su' and 'su -' allowing you to see perl points to a PATH issue.

If you execute 'su -' you are sourcing the profile of the user to which you are switching, otherwise you are not.

As Gordon said, you need to add perl to your path. It maybe that perl is installed in '/opt/perl/bin/perl' but this isn't in your path. An easy choice is to create a symbolic link :

# ln -s /opt/perl/bin/perl /usr/bin/perl

Now, since '/usr/bin' will be in your path, so will 'perl'.

Regards!

...JRF...