Skip to main content

Extracting Output in Shell [Resolved]

When I am doing

ls -la |grep -e Aug

I am getting the output as

-rw-r--r--    1 root           staff   454 Oct 15 18:35 Aug.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 25 04:00 abc7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 26 07:00 def7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 27 10:00 ghi7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 28 13:00 jkl7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 29 16:00 mno7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 30 19:00 pqr7.txt

I only want to list the files which are created on Aug not the first file which is created on Oct but has name Aug in it. Below should be the output

-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 25 04:00 abc7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 26 07:00 def7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 27 10:00 ghi7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 28 13:00 jkl7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 29 16:00 mno7.txt
-rwxr-xr-x@   1 PrashastKumar  staff     0 Aug 30 19:00 pqr7.txt

Also i want to take the month as user input not the hardcoded value.


Question Credit: Prashast
Question Reference
Asked October 15, 2017
Tags: shell
Posted Under: Unix Linux
40 views
2 Answers

This one worked for me

ls -al | awk '$6 == "Aug" {print}'

credit: Prashast
Answered October 15, 2017
 
@JeffSchaller Thanks; this answer was actually posted about eight seconds before mine, though. – Eliah Kagan 9 mins ago
 CanDoerz  1 month ago
 
No need to repeat it; just vote up and accept Eliah's answer. – Jeff Schaller 15 mins ago
 CanDoerz  1 month ago
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA