AWK filter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK filter
# 1  
Old 11-18-2010
Bug AWK filter

Hi I am using the following to get the filename

HTML Code:
ls -lrt filename* | tail -1 | awk {'print$9'}
o/p : filename-20101117

want to extract 20101117 from the filename ..

Pls advise
# 2  
Old 11-18-2010
Code:
ls -lrt filename* | tail -1 | awk {'print$9'} | cut -d'-' -f2

# 3  
Old 11-18-2010
Code:
ls -lrdt filename* | sed -n '$s/.*-//p'

or rather:
Code:
ls -ldt filename* | sed 's/.*-//;q'


Last edited by Scrutinizer; 11-18-2010 at 05:50 AM.. Reason: Changed order (thanks Franklin)
# 4  
Old 11-18-2010
Quote:
ls -lrt filename* | tail -1 | awk '{print $9}' | awk -F "-" '{print $2}
the same if you want to use awk only
# 5  
Old 11-18-2010
Code:
ls -lt filename* | awk -F- 'NR==1{print $NF}'

# 6  
Old 11-18-2010
Code:
ls -lrdt filename* | awk -F- '{p=$NF}END{print p}'

---------- Post updated at 10:43 ---------- Previous update was at 10:42 ----------

Quote:
Originally Posted by Franklin52
Code:
ls -lt filename* | awk -F- 'NR==1{print $NF}'

Morning Smilie Smilie

Last edited by Scrutinizer; 11-18-2010 at 05:49 AM..
# 7  
Old 11-18-2010
Bug

HTML Code:
ls -lrt filename* | awk -F- 'NR==1{print $NF}'
the o/p comes at 20101116.txt

HTML Code:
ls -lrt filename* | awk -F- 'NR==1{print $NF}' | cut -d'.' -f2
o/p txt

I require only 20101116 as o/p
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter using awk in CSV files

Hello Gentlemen, Finding difficulties to play with my Input files:confused: . Your guidance will certainly help as always. After converting to csv file from XLSM file, I am getting some extra ""(double quote) characters which I want to terminate inside shell script and process it further. ... (6 Replies)
Discussion started by: pradyumnajpn10
6 Replies

2. Shell Programming and Scripting

Filter and sort the file using awk

I have file and process it and provide clean output. input file Device Symmetrix Name : 000A4 Device Symmetrix Name : 000A5 Device Symmetrix Name : 000A6 Device Symmetrix Name : 000A7 Device Symmetrix Name : 000A8 Device Symmetrix Name : 000A9 Device Symmetrix Name ... (10 Replies)
Discussion started by: ranjancom2000
10 Replies

3. Shell Programming and Scripting

Use of awk or sed to filter out the ouput

Hi, i am trying to get the system model with the help of awk : $ prtconf | awk '/^System Model/' System Model: IBM,8408-E8D but i want just the below outout that is command should chk for pattern <IBM,> and remove it from the final output : System Model:8408-E8D Can... (2 Replies)
Discussion started by: omkar.jadhav
2 Replies

4. Shell Programming and Scripting

Use of awk to filter out the command output

Hi All, I am trying to find out number of cores present for hp-ux server from the output of print_manifest (as shown below). i suppose awk will be best tool to use for filtering. output of print_manifest is : System Hardware Model: ia64 hp Integrity Virtual Partition ... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

5. Shell Programming and Scripting

Filter column using awk

Hi all: How do I use an `awk` like: awk '{print $1 "\t" $2}' input on the following input: <head>medium-n</head> nmod+ns+ns-map-n <head>future-n</head> of+n-the+ns-map-n to achieve the following desired output: medium-n nmod+ns+ns-map-n future-n of+n-the+ns-map-n (3 Replies)
Discussion started by: owwow14
3 Replies

6. Shell Programming and Scripting

Help with awk, using a file to filter another one

I have a main file: ... 17,466971 0,095185 17,562156 id 676 17,466971 0,096694 17,563665 id 677 17,466971 0,09816 17,565131 id 678 17,466971 0,099625 17,566596 id 679 17,466971 0,101091 17,568062 id 680 17,466971 0,016175 17,483146 id... (4 Replies)
Discussion started by: boblix
4 Replies

7. Shell Programming and Scripting

awk-filter record by another file

I have file1 3049 3138 4672 22631 45324 112382 121240 125470 130289 186128 193996 194002 202776 228002 253221 273523 284601 284605 641858 (8 Replies)
Discussion started by: biomed
8 Replies

8. Shell Programming and Scripting

awk: assign variable with -v didn't work in awk filter

I want to filter 2nd column = 2 using awk $ cat t 1 2 2 4 $ VAR=2 #variable worked in print $ cat t | awk -v ID=$VAR ' { print ID}' 2 2 # but variable didn't work in awk filter $ cat t | awk -v ID=$VAR '$2~/ID/ { print $0}' (2 Replies)
Discussion started by: honglus
2 Replies

9. Shell Programming and Scripting

Filter values by Awk

INPUT A EEEE A EEEE A EEEE B FFFF B GGGG B FFFF C GGGG C FFFF C FFFF D HHHH D XXXX D YYYY D YYYY E EEEEE E EEEEE E EEEEE (5 Replies)
Discussion started by: repinementer
5 Replies

10. UNIX for Dummies Questions & Answers

Filter using awk

Hi, I need to filter the output of a command and display omitting the first 6 lines and the last two lines..How can i do this using awk. command | awk ' NR > 7' will omitt the first 6 lines but dont know how to omit the last two lines.. can anyone help? (3 Replies)
Discussion started by: arun_st
3 Replies
Login or Register to Ask a Question