Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-23-2012, 12:56 PM   #1
LQ Newbie
Registered: May 2012
Posts: 28

Rep: Reputation: Disabled
matching and printing specific lines

I have been trying to do this for sometime now but I have not been able to do it. Say I have a file named 'John', with content like this:
and I have other files with each file listed from 1- 50000 like this:
file A
1 0
2 1
3 0
4 0
5 0
6 0
7 0
8 0
9 1
10 0
.  1
.  0
.  1
50000  0
I have many of such files A but with different filenames. These are all in the same directory.
I want to use file named "john" to compare field 1 in file A and all the other files like this: wherever you have 6 in filed 1 file A print entire line, then take 10 from file John look for 10 in file A and print line. Output will look like this:
6 0
10 0
This comparism is then done for each other file
Thanks all
Old 08-23-2012, 01:02 PM   #2
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
is this homework ? what have you tried so far ? where are you stuck ?

look into the -f and -w parameters of the grep command.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing $ Lines After Finding Specific Pattern pravin.bhande Programming 6 04-12-2012 10:20 AM
[SOLVED] awk with pipe delimited file (specific column matching and multiple pattern matching) lolmon Programming 4 08-31-2011 12:17 PM
Printing specific lines of a file using script. barunparichha Linux - Software 6 05-20-2009 12:31 AM
Sed command to print matching lines and 2 lines above.. DX398 Programming 12 10-01-2008 08:25 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration