?
Solved

Help for a  unix  command

Posted on 2013-05-10
2
Medium Priority
?
343 Views
Last Modified: 2013-05-11
Hi,

I am using the below command from a shell script to find file date.


Filedate=`ls -l /usr/home/test/sample.txt | awk '{ print $6 $7}'` ;

echo $Filedate


But it is printing  for ex:

May9   instead of May09

Can anyone please  let me know how to fix this..
0
Comment
Question by:new_perl_user
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
pony10us earned 2000 total points
ID: 39155895
Taking a wild guess since I don't have access to my Unix box here to test:

Filedate=`ls -l /usr/home/test/sample.txt | awk '{ print $6 ("%02d\n", $7)}'` ; 
echo $Filedate

Open in new window


the ("%02d\n", $7) should create 2 digit with leading zero's for the date I believe.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39157762
My awk (on Ubuntu) threw a syntax error with this.  A more usual way to do this would be:
Filedate=`ls -l /usr/home/test/sample.txt | awk '{ printf "%s%02d\n", $6, $7}'`

Open in new window

By the way, the above still doesn't work on Ubuntu because the date in an "ls -l" is given as YYYY-MM-DD rather than a separate Month and Day.  This also confuses people who assume that the filename is $9 in "ls -l" - in Ubuntu it starts at $8. For example
$ ls -l /etc/hosts
-rw-r--r-- 1 root root 1939 2013-02-15 09:56 /etc/hosts

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question