How to fetch a specific line from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to fetch a specific line from file
# 1  
Old 02-01-2011
How to fetch a specific line from file

Hi,
I have text file in the following strucher .
The files contain hondreds of lines.

value1;value2;value3;value4

I would like to get back the line with lowest date (values4 field).
In this case its line number 3.

groupa;Listener;1;20110120162018
groupb;Database;0;20110201122641
groupc;job_q_processes;2;20101210111928
groupd;job_scheduler;0;20110201122641

Thanks
# 2  
Old 02-01-2011
Try this,
Code:
sort -t";" -nk4 inputfile | head -1

# 3  
Old 02-01-2011
Code:
awk -F';' 'BEGIN {getline; line=$0; low=$4} {if ($4 < low) { line=$0 } } END {print line}' yourfile

# 4  
Old 02-01-2011
Code:
awk -F\; 'NR==1{s=$0;m=$4}$4<m{m=$4;s=$0}END{print s}' file

# 5  
Old 02-01-2011
Another awk:
Code:
awk -F\; 'BEGIN{L=99999999999999}$NF<=L{r=$0;L=$NF}END{print r} file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to fetch specific data from a file.?

Hi , I have a file which contains 2 days logs(here it is 24 and 25) I want to list data only for date 25 fron the file. please suggest me how should i get this. file content mentioned below 17-05-24 Name Succ Fail 00:00:29 ... (5 Replies)
Discussion started by: scriptor
5 Replies

2. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

3. Shell Programming and Scripting

How to fetch values from a line in a file to variables in UNIX?

Hi, I need to assign values from a lines in a file into variables in unix, i am using Korn shell. I tried the below script from posts but i am unable to fetch every value in a variable. #! /usr/bin/ksh #for file in test.txt; do IFS=$'\|' I=1 while read -a val do echo... (15 Replies)
Discussion started by: karthikram
15 Replies

4. Shell Programming and Scripting

Fetch entries with specific pattern

Hi all, I have following sample input file which is a part of big file: ID AINX_HUMAN Reviewed; 499 AA. AC Q16352; B1AQK0; Q9BRC5; DT 30-MAY-2000, integrated into UniProtKB/Swiss-Prot. DT 23-JAN-2002, sequence version 2. DT 28-NOV-2012, entry version 123.... (2 Replies)
Discussion started by: kareena
2 Replies

5. Shell Programming and Scripting

Fetch specific entries

Hi Guys This time my input sample from a Big file like this In TTDS00002 UniProt ID P11229 TTDS00002 Name Muscarinic acetylcholine receptor M1 TTDS00002 Type of target Successful target TTDS00002 Synonyms M1 receptor TTDS00002 Disease Alzheimer's disease... (13 Replies)
Discussion started by: Priyanka Chopra
13 Replies

6. Shell Programming and Scripting

Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as (7 Replies)
Discussion started by: manigrover
7 Replies

7. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

8. Shell Programming and Scripting

How to fetch specific fields

Dear Friends, Please provide some commands to fecth specific filed (data yellow color) from below data.. Input data 2648: 1;20120707;3591|4;20290107;90|5;20290107;3|9;20120705;0|10;20120705;0|16;20290113;15|29;20120705;0 2658: 1;20120722;0|4;20290422;1200|9;20120705;0|10;20120705;0 2646:... (4 Replies)
Discussion started by: suresh3566
4 Replies

9. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

10. Shell Programming and Scripting

To fetch specific words from a file

Hi All, I have a file like this,(This is a sql output file) cat query_file 200000029 12345 10001 0.2 0 I want to fetch the values 200000029,10001,0.2 .I tried using the below code but i could get... (2 Replies)
Discussion started by: girish.raos
2 Replies
Login or Register to Ask a Question