Using awk to get folder name and date fields with heading


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using awk to get folder name and date fields with heading
# 1  
Old 03-19-2015
HP Using awk to get folder name and date fields with heading

It is on the HP-Unix

Output desired:

Code:
Folder Name   Date
Folder1          Mar 18 10:00
Folder2          Mar 17 12:23

Tried with
Code:
 ls -ldt wp411*  |  awk '{print $9,"\t",$6," ",$7," "$8}'

Please help me with the headings

Last edited by Scrutinizer; 03-19-2015 at 04:39 AM.. Reason: CODE tags
# 2  
Old 03-19-2015
Hello Siva SQL,

Please use code tags for commands/codes/Inputs in your posts. Following may help you in same didn't test though.
Code:
ls -ldt wp411* | awk 'BEGIN{print "Folder Name Date"} {print $9,"\t",$6," ",$7," "$8}'

Thanks,
R. Singh
# 3  
Old 03-19-2015
Code:
user@server1:$ ls -ldt wp411* | awk 'BEGIN{print "Folder Name \t\t Date"} {print $9,"\t",$6," ",$7," "$8}'
Folder Name              Date
wp411.0_20150311/        Mar   11  00:31
wp411.0_20150304/        Mar   4  01:27
wp411.0_20150302_ms02/          Mar   2  14:14
wp411.0_rev01_20150301/          Mar   1  19:34

How to correct the alignment ?
# 4  
Old 03-19-2015
Try
Code:
ls -ld wp411* | awk 'BEGIN{printf "%-20s %s\n", "Folder Name", "Date"} {printf "%-20s %s %s %s\n", $9, $6,$7, $8}'

You will need to know the max length of the folder names, though.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

3. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

4. UNIX for Dummies Questions & Answers

Sorting on fields for last date

Hi all, I have a file with a list of rpm's that have different dates. I am trying to just grab the latest rpm and install date, and discard the rest. The file has 1000's of entries all with different names and dates. I have tried sort -k on the file and I am not grabbing the info, ... (4 Replies)
Discussion started by: gartie
4 Replies

5. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

6. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

7. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

8. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

9. Shell Programming and Scripting

getting the date fields in Perl

I get the perl date in the following format: Mon Jan 31 06:01:37 2005 How can I extract each field in a single line using a regular expression?? I dont want to use "split". Any other way out?? JP :) (2 Replies)
Discussion started by: jyotipg
2 Replies

10. Shell Programming and Scripting

Stripping date fields

How would I strip a date field? For example, if I have TODAY defined as the following: TODAY=`date +"%m/%d/%y"`, TODAY is assigned the value 11/01/03 on Nov 1, 2003 How would I strip the first 2 bytes? (11)? Thank you in advance for the help. (6 Replies)
Discussion started by: Latha Nair
6 Replies
Login or Register to Ask a Question