How to extract a field from ls-l command and display?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract a field from ls-l command and display?
# 1  
Old 04-12-2011
How to extract a field from ls-l command and display?

So I want to put a line at the end of my script which greps for keywords from syslog.log that outputs the following after it is done:

"This file was last modified on (thisdate)"

I know I can use the following to get the date:

Code:
rtidsvb(izivanov):/home/izivanov> ll /var/adm/syslog/syslog.log 
-rw-r--r--   1 root       root        503064 Apr 12 12:06 /var/adm/syslog/syslog.log

I know I can use cut -f5 -f6 to get just the date but don't know how. How can I use that and input it into the line in the script for (thisdate)? Or is there an easier way to input date of the file.

I'm relatively new to scripting and UNIX...

Thanks a bunch...
# 2  
Old 04-12-2011
try using
Code:
ll | awk '{print $6$7$8}'

This User Gave Thanks to jville For This Post:
# 3  
Old 04-12-2011
Thank you so much...and how do I put spaces in the code between $6$7$8 so that I would separate fields for better visual purposes?

---------- Post updated at 03:13 PM ---------- Previous update was at 03:11 PM ----------

Never mind, I got it. You put them under quotes.
# 4  
Old 04-13-2011
GNU date has -r option to display modification date of a file:
Code:
date -r /var/adm/syslog/syslog.log "+%D at %T"

# 5  
Old 04-13-2011
Solved

Solved
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command to extract empty field in a large UNIX file?

Hi All, I have records in unix file like below. In this file, we have empty fields from 4th Column to 22nd Column. I have some 200000 records in a file. I want to extract records only which have empty fields from 4th field to 22nd filed. This file is comma separated file. what is the unix... (2 Replies)
Discussion started by: rakeshp
2 Replies

2. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

3. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

4. Shell Programming and Scripting

extract data and display the missing value

Hi, I have thousands of data in 1 file that need to be sorted out. My file is like below:- File1.txt condition 1 scaf_27 CDS 48317 48517 "e_gww2.27.12.1" Id 35277 scaf_27 stop_cod 48317 48319 "e_gww2.27.12.1" scaf_27 CDS 48518 49107 "e_gww2.27.12.1" ... (4 Replies)
Discussion started by: redse171
4 Replies

5. Shell Programming and Scripting

Read File and Display The Count of a particular field

Hi Mates, I require help in the following: I have the following file snmp.txt Wed Mar 2 16:02:39 SGT 2011 Class : mmTrapBladeS origin : 10.0.0.0 hostname : 10.0.0.2 msg : IBM Blade Alert: Calendar Index : 10.0.0.2-IBMBLADE Fri Mar 4 07:10:54 SGT 2011 Class : mmTrapBladeS... (2 Replies)
Discussion started by: dbashyam
2 Replies

6. Shell Programming and Scripting

How to only display lines where a field has the highest number?

Hello Wondering if anybody can advise me how I can sort the below file so it only displays lines with the latest versions of an object? As you'll see some of the scripts listed in my file have more than one version number (version number is after the file extension). E.g. cdm_bri.pkb has... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

7. UNIX for Dummies Questions & Answers

Awk help needed for display particular field alone for searching pattern

Hi, I have a requirement for taking an particular number in a log file. if i grep for the particular string it will retrieve the entire line for the particular string. but i want to display only the string from each line which i am searching for, Note: The searching field varies its position... (3 Replies)
Discussion started by: senthilkumar_ak
3 Replies

8. Shell Programming and Scripting

using awk make an field as 5 digit and display

using awk convert 3 rd fileld of file as 5 digit and then display changed file. like 1 2 23445 3452 3343 3 5 6 6 ================ o/p:- 1 2 23445 3452 03343 3 5 00006 6 (1 Reply)
Discussion started by: RahulJoshi
1 Replies

9. Shell Programming and Scripting

display file where 4th field = 200704

Hello I have a file which is pipe delimited. The 4 th field has value like 200704 or 200705 etc. Now i have to get only those records where 4th field is 200704 How can i do this? I have to get the whole record where 4th field = 200704 (7 Replies)
Discussion started by: vasuarjula
7 Replies

10. AIX

display file where 4th field = 200704

Hello I have a file which is pipe delimited. The 4 th field has value like 200704 or 200705 etc. Now i have to get only those records where 4th field is 200704 How can i do this? I have to get the whole record where 4th field = 200704 (4 Replies)
Discussion started by: vasuarjula
4 Replies
Login or Register to Ask a Question