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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk within variable 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hello everyone,

could you help me out with a little problem (I'm quite new to perl):

I got the following output:
(Note: I'm using AIX / Linux)

Code:
ls -all /datastore/backup

-rw-r--r-- 1 root root 6431369457 Jul 10 07:57 /datastore/backup

What I'd like to do is store only the "Jul 10" in a variable ...

Cutting it out is easy:

Code:
ls -all /datastore/backup | awk '{print $6 " " $7}'

But how do I get this stored within a variable ?

Using the following stores the whole string within the variable and NOT only the "Jul 10":

Code:
$dat2=`ls -all /datastore/backup | awk '{print $6 " " $7}'`;
print $dat2, "\n";

-rw-r--r-- 1 root root 6431369457 Jul 10 07:57 /datastore/backup

Regards,
Thomas Schmitt
 
Hi

Just to correct your code, escape the dollar signs ( $ ) :
Code:
[navy]$dat2[/navy][teal]=[/teal]`ls [teal]-[/teal]all [green][i]/datastore/[/i][/green]backup [teal]|[/teal] awk [green][i]'{print [highlight]\[/highlight]$6 " " [highlight]\[/highlight]$7}'[/i][/green]`[teal];[/teal]

But would be preferable to forget such shell scripting practices when coding in Perl.

In case /datastore/backup is a single file to check, this will print its modification time in local date time format :
Perl:
[navy]@stat[/navy][teal]=[/teal][b]stat[/b] [green][i]'/datastore/backup'[/i][/green][teal];[/teal]
[b]print[/b] scalar localtime [navy]$stat[/navy][teal][[/teal][purple]9[/purple][teal]];[/teal]


Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top