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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting fetch last line no form file which is match with specific pattern by grep command
# 8  
Old 02-01-2011
Hi pravin

Thanx a lot buddy

can you plz explain this portion of command

$1FS$2 =="Nov 3"

it is working Smilie
# 9  
Old 02-01-2011
Hi,
Code:
$1FS$2=="Nov 3"

$1 is the first field i.e Nov and $2 is second field i.e 3 and FS is field separator.
So, above condition will check $1FS$2 is equal to Nov 3 then assign record number to variable i. Once finished processing of input file , it will print value of i.
# 10  
Old 02-01-2011
one more doubt buddy

if i run this
var5=`awk '$1FS$2 =="Dec 2" {i=NR} END {print i}' input file` then it working fine

but if i run in this way

var="Dec 3"
var5=`awk '$1FS$2 =="$var" {i=NR} END {print i}' input file` then it is not giving any outputSmilie
# 11  
Old 02-01-2011
Use -v option with awk
Code:
var5=`awk -v var="Dec 3" '$1FS$2 ==var {i=NR} END {print i}' input file`

# 12  
Old 02-01-2011
there is problem pravin

Hi

my code type is this in var3 i calulate date

var3=$Month1" "$day # var3=Dec 3

Max_LIneNo=`awk -v var="$var3" '$1FS$2 ==$var {i=NR} END {print i}' input File`

but it throw error "it is not correct."
# 13  
Old 02-01-2011
remove $ ... Please check post #11
Code:
Max_LIneNo=`awk -v var="$var3" '$1FS$2 ==$var {i=NR} END {print i}' input File`

This User Gave Thanks to pravin27 For This Post:
# 14  
Old 02-01-2011
thanx buddy
you helped me alotSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Fetch latest version form a file?

Hi, I have a file where versions will be updated, i need to get latest/last updated version from that file. Could you please help? File looks like below - <versions> <version>R20180417.006</version> <version>R20180421.007</version> <version>R20180421.008</version> ... (5 Replies)
Discussion started by: schandra128
5 Replies

2. Shell Programming and Scripting

Match all lines in file where specific text pattern is less than

In the below file I am trying to grep or similar, all lines where only AF= is less than 0.4.. Thank you :). grep grep "AF=" ,+ .4 file file 12 112036782 . T C 34.0248 PASS ... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Grep pattern after specific line number in a file

Hi guys, I am running a while loop in a script ro read a file line by line. Now I want to run a grep only on the lines below the line I am that is being read by the while loop. Eg: If my while loop is on line 4 of the file, the grep only runs below line 4 and does not include line 1,2... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

4. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

5. 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

6. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

7. 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

8. Shell Programming and Scripting

Help with replace line based on specific pattern match

Input file data20714 7327 7366 detail data20714 7327 7366 main data250821 56532 57634 detail data250821 57527 57634 main data250821 57359 57474 main data250821 57212 57301 main data250821 57140 57159 detail data250821 56834 57082 main data250821 56708 56779 main ... (3 Replies)
Discussion started by: perl_beginner
3 Replies

9. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: yoavbe
4 Replies

10. Shell Programming and Scripting

Merge two file data together based on specific pattern match

My input: File_1: 2000_t g1110.b1 abb.1 2001_t g1111.b1 abb.2 abb.2 g1112.b1 abb.3 2002_t . . File_2: 2000_t Ali england 135 abb.1 Zoe british 150 2001_t Ali england 305 g1111.b1 Lucy russia 126 (6 Replies)
Discussion started by: patrick87
6 Replies
Login or Register to Ask a Question