Extract lines that have entries in VI file

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extract lines that have entries in VI file
# 1  
Old 12-20-2016
Extract lines that have entries in VI file

Dears experts

i have UNIX file that contain 4 million lines , i need to extract all lines that have entiries saved in VI file , i have below comand but it takes tooooo long time :

Code:
for i in `cat file1.csv`; do cat dump | grep -i  $i >> file2.csv; done

where :
file1.csv = VI file that contain entries to be used for search.
file2.csv = output file.

dump = the name of the dump

example for entry in dump :

Code:
IP101MURB-I:1-1-4-13,11-409-0687,capCoupling,2016-12-11 19:01:00,50
IP101MURB-I:1-1-4-13,11-409-0687,degraded,2016-12-11 19:01:00,50
IP101MURB-I:1-1-5-27,11-406-7432,capCoupling,2016-12-11 19:01:00,50

example for entry in VI file :
Code:
IP101MURB-I:1-1-4-13

example output file contain :

Code:
IP101MURB-I:1-1-4-13,11-409-0687,capCoupling,2016-12-11 19:01:00,50
IP101MURB-I:1-1-4-13,11-409-0687,degraded,2016-12-11 19:01:00,50


note that i need all lines that have this entry.

Thanks in advance




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
DON'T overuse pointless FONT tags

Last edited by RudiC; 12-20-2016 at 10:12 AM.. Reason: Added CODE & Changed FONT tags.
# 2  
Old 12-20-2016
How about using VI as a pattern file with grep's -f option:
Code:
grep -if file1.csv dump > file2.csv

# 3  
Old 12-20-2016
Hi Rudic

i gt this error :

Code:
-bash-3.00$ grep -if dec18PND.csv EP-ports-faults_20161218.csv  >  file2.csv
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
-bash-3.00$

Moderator's Comments:
Mod Comment SERIOUSLY: Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-20-2016 at 10:24 AM.. Reason: Added CODE tags.
# 4  
Old 12-20-2016
It is always helpful to support a request with system info like OS and shell, preferred tools, and adequate sample input and output data to avoid ambiguities and keep people from guessing.

So please provide your OS and grep version.
# 5  
Old 12-20-2016
On Solaris use /usr/xpg4/bin/grep rather than grep
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 12-20-2016
here is the OS

-bash-3.00$ uname -a
Code:
SunOS ALU_STC_GW 5.10 Generic sun4u sparc SUNW,Sun-Blade-100
-bash-3.00$

i dont know how to get grep version , however i found this fgrep and when i use it cmmand accepted but produce output file with zero bytes :
Code:
fgrep infile2.csv EP-ports-faults_20161218.csv > outfile2.csv

the output file show 0 :
Code:
-rw-r--r--   1 motive   other          0 Dec 20 19:06 outfile2.csv
-rw-r--r--   1 motive   other      47763 Dec 20 19:07 outfile.csv

---------- Post updated at 12:12 PM ---------- Previous update was at 12:02 PM ----------

Quote:
Originally Posted by Scrutinizer
On Solaris use /usr/xpg4/bin/grep rather than grep

hello Scrutinizer

i did but i copied the whole file as it is :

Code:
-rw-r--r--   1 motive   other    223682851 Dec 18 08:09 EP-ports-faults_20161218.csv

-rw-r--r--   1 motive   other    223682851 Dec 20 19:24 outfile3.csv

# 7  
Old 12-20-2016
man grep:
Quote:
OPTIONS
Generic Program Information
--help Output a usage message and exit.

-V, --version
Output the version number of grep and exit.
Does /usr/xpg4/bin/grep offer the -f option? If yes, create small but representative samples of dump and VI files each, run the command and post the results.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract lines from a file

Hi all; Here is my file which contains a list of files (recent versions of files are in red). This file is dynamic, files versions can change at any time (versions can increment) filename ------------------------------------------------------- ... (8 Replies)
Discussion started by: chercheur111
8 Replies

2. Shell Programming and Scripting

Want to extract certain lines from big file

Hi All, I am trying to get some lines from a file i did it with while-do-loop. since the files are huge it is taking much time. now i want to make it faster. The requirement is the file will be having 1 million lines. The format is like below. ##transaction, , , ,blah, blah... (38 Replies)
Discussion started by: mad man
38 Replies

3. Shell Programming and Scripting

How to extract certain lines from a file?

Hi guys I have a several thousands line file in the following format: n817 -------------------------------------------------- n842 -------------------------------------------------- n877 -------------------------------------------------- n513 /bb/data/rmt2db.lrl:JBSKDB 31915 75... (4 Replies)
Discussion started by: aoussenko
4 Replies

4. Shell Programming and Scripting

Extract particular lines from a file

Hi all, I have a file with many records with information as given below ID A16L2_HUMAN Reviewed; 619 AA. AC Q8NAA4; A5PL30; B2RPK5; Q658V4; Q6PID3; Q8NBG0; DT 20-MAY-2008, integrated into UniProtKB/Swiss-Prot. DT 20-MAY-2008, sequence version 2. DT ... (1 Reply)
Discussion started by: kaav06
1 Replies

5. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

6. Shell Programming and Scripting

To extract the required lines from a file

I have a files in a directory in this format data data data ---BEGIN CERT----- data data data ---END CERT ----- Now, I want to extract the lines starting from --BEGIN CERT-- and write the contents till the end of file into a new file.How can I do this for all the files in the... (1 Reply)
Discussion started by: sureshg
1 Replies

7. Shell Programming and Scripting

Extract lines from a file automatically. Please a Help

hello, hope you can help me: ive got a file called archivos The content or structure of this file is ./chu0/filechu ./chu1/filechu I extract each line from this file manually and redirect to a file, and it Works fine, so the command line is: awk ‘/chu0/ {print $0}' < archivos >... (8 Replies)
Discussion started by: alexcol
8 Replies

8. Shell Programming and Scripting

How to extract a sequence of n lines from a file

Hi I want to be able to extract a sequence of n lines from a file. ideas, commands and suggestions would be highly appreciated. Thanks (4 Replies)
Discussion started by: 0ktalmagik
4 Replies

9. Shell Programming and Scripting

how to extract a range of lines from a file

I am reading a file that contains over 5000 lines and I want to assign it to a shell variable array (which has a restriction of 1024 rows). I had an idea that if I could grab 1000 record hunks of the file, and pipe the records out, that I could perform a loop until I got to the end and process 1000... (5 Replies)
Discussion started by: beilstwh
5 Replies

10. UNIX for Dummies Questions & Answers

extract specific lines from file

hi, how would i extract a range of lines in a file by using the line number? ex: file contains: 1 title 2 i want 3 this part 4 to be taken out 5 from this file 6 and sent to 7 another file 8 not needed 9 end of file In this case, i want to copy line number 2 to 7 on a new... (2 Replies)
Discussion started by: apalex
2 Replies
Login or Register to Ask a Question