Retriving the first line of data from the listing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retriving the first line of data from the listing
# 1  
Old 10-25-2010
Retriving the first line of data from the listing

Hi All,

I have a problem of retrieving the first line of data from the listing i got back from this command :

ls -l * | awk '{print $9}' | awk -F. '{print $3}' | sort -g

the files names are in the folder are like
month.dat.201010210400
day.dat.201010210401
year.dat.201010210402

As the folders contains other files which doesn't match the pattern ,
i get back results with blanks spaces in front of the listing .
eg :



201010210400
201010210401
201010210402

how do i omit the blanks spaces and read the first line of data from the result ? i tried using 'head -1' but it is returning me the blank row

Thanks
# 2  
Old 10-25-2010
Code:
ls *dat* |awk -F \. '{print $NF}'

or you prefer to use ls -l

Code:
ls -l * |awk -F \. '/dat/ {print $NF}'

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 10-25-2010
Thanks , it solve my problems Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

2. Shell Programming and Scripting

Help in adding a data after a particular line of data in a file.

Hi.. I'm into a bump after trying to solve this prob.. i've a file with contents like below. <blankline> 'pgmId' : 'UNIX', 'pgmData' : 'textfile', 'author' : 'admin', ....... Now i'm trying to insert a new data after pgmId. so the final output will be... (7 Replies)
Discussion started by: arjun_arippa
7 Replies

3. UNIX for Advanced & Expert Users

listing in 1 line

hi when I do ps -aef | grep .... I get the different parts each on 1 line. if I do a=`ps -aef | grep ...` echo $a I receive the result on 1 line. how to display it as before? i.e. each on 1 line? thx (2 Replies)
Discussion started by: melanie_pfefer
2 Replies

4. UNIX for Dummies Questions & Answers

Directorie listing in Human form for data sizes

I have seen it done at my job before, there is a command that will make a notepad and show the directorie path, subfolders, and size of the subfolders? But i dont want it to go lower than 2 levels for example: folder_01 10 GB subfolder_02 10 GB subfolder_03 10 GB... (4 Replies)
Discussion started by: JUSSAN007
4 Replies

5. UNIX for Dummies Questions & Answers

Listing out three fields of data

How would I find three different fields in a data file such as first name, last name, credit card number in a particular file? Thanks in advance for your help (3 Replies)
Discussion started by: damion
3 Replies

6. Linux

Error While retriving Host details from Nagios

Whoops! Error: Could not read object configuration data! Here are some things you should check in order to resolve this error: 1. Verify configuration options using the -v command-line option to check for errors. 2. Check the Nagios log file for messages relating to startup or... (0 Replies)
Discussion started by: manian_balu
0 Replies

7. Shell Programming and Scripting

retriving a value from a variable

Hi all, I need to retrive a value from a variable like so temp1=test1 temp2=test2 num=2 while do pingvar=eval echo \$temp$num echo $pingvar let num=$num-1 done in the "echo $pingvar" i get $temp2 and $temp1 but, I need to get the values of temp2 and temp1 which are test1 and... (2 Replies)
Discussion started by: afadaghi
2 Replies

8. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

9. UNIX for Dummies Questions & Answers

Listing words from a file on a Separate Line

Hi, I want to list all the words in my file on a separate line. I am using the bourne(sh)/bourne again shell(bash). Thanks, theA (2 Replies)
Discussion started by: Astudent
2 Replies
Login or Register to Ask a Question