Solved

Help for a  unix  command

Posted on 2013-05-10
2
340 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
2 Comments
 
LVL 26

Accepted Solution

by:
pony10us earned 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
winscp 000webhost.com 6 99
Apache LDAP Authentication 20 53
Migrating a Linux server to VMware 3 110
Renaming with batch file 9 78
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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