Multiple search in one command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple search in one command
# 1  
Old 12-17-2012
Multiple search in one command

I have a multiple csv files which have different network time. The files are in sequance,
The Files Look like..
Code:
csv 1
network time
1348177401922972
1348177401949917
1348177401959150
1348177401964104
1348177401964258
1348177401964289
1348177401969053
1348177401970286
1348177401971174
1348177401971576
1348177401971686
1348177401972457
1348177401973465
1348177401973616

Code:
csv 2
network time
1348177401974543
1348177401976294
1348177401977086
1348177401977232
1348177401977262
1348177401977294
1348177401977924
1348177401978096
1348177401978418
1348177401978450
1348177401978476
1348177401978501
1348177401978526
1348177401978825
1348177401978880

Code:
csv 3
network time
1348177401978905
1348177401978928
1348177401978952
1348177401978975
1348177401979000
1348177401979022
1348177401979046
1348177401979071
1348177401979210
1348177401979548
1348177401979880
1348177401980625
1348177401982222
1348177401982953

Now, I have a five network time for search e.g. 1348177401949916, 1348177401971173, 1348177401977923 ,1348177401978974, 1348177401979879

I want to find five network time which is less than or equal to OR near by search time from multiple file using one command.

so, output wiil be
Code:
1348177401949917
1348177401971174
1348177401977924
1348177401978975
1348177401979880

Please help.
Thanks in advance for your answers.

Last edited by rakesh_arxmind; 12-17-2012 at 09:19 AM..
# 2  
Old 12-17-2012
This is not a single line command, but this awk code will get you the desired output. I hope this helps.
Code:
awk ' BEGIN {
 str="1348177401949916,1348177401971173,1348177401977923,1348177401978974,1348177401979879";
 split(str,ARR,",");
 } {
 for(i=1;i<=5;i++) {
  val=sprintf ("%s",ARR[i]);
  if(($1==val)||($1==val+1)||($1==val-1))
   print $1;
 }
} ' csv*


Last edited by Yoda; 12-17-2012 at 01:14 PM.. Reason: code indentation
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with search and replacing multiple items in multiple files

Im having an issue when trying to replace the first column with a new set of values in multiple files. The results from the following code only replaces the files with the last set of values in val.txt. I want to replace all the files with all the values. for date in {1..31} do for val in... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

3. Shell Programming and Scripting

Command to Search a FILE for a STRING in multiple DIRECTORIES

Hi, Can someone please help me with a Command to Search a FILE for a STRING in multiple DIRECTORIES. I am searching for the VIP in HTTPD.CONF in multiple httpd instances. I am using find ./ -name "httpd.conf" | xargs grep 10.22.0.141 cut -d: -f3- | cut -d ' ' -f4 | sort | uniq -c ... (1 Reply)
Discussion started by: crosairs
1 Replies

4. UNIX for Dummies Questions & Answers

Search file and print everything except multiple search terms

I'm trying to find a way to search a range of similar words in a file. I tried using sed but can't get it right:sed 's/\(ca01\)*//'It only removes "ca01" but leaves the rest of the word. I still want the rest of the information on the lines just not these specific words listed below. Any... (3 Replies)
Discussion started by: seekryts15
3 Replies

5. Linux

How to search multiple word using grep command?

How to search multiple word using grep command for example i want to reserch ANJ001 AA Using ridiculous font, size, and color changes instead of normal space separated text and CODE tags obfuscates what you are trying to do and makes it difficult for volunteers who may want to help you solve... (1 Reply)
Discussion started by: na.dharma
1 Replies

6. Shell Programming and Scripting

Multiple search options in find command

Hi, I'd like find multiple file options to fetch different types of files. find /path...// -type f -name "*.log" -o -name "*.req" -o -name "*.txt" -mtime +5 -exec ls -l {} \; Where as in the above command only the last .txt files its retriving but not .log and .req files can body help... (1 Reply)
Discussion started by: Y.balakrishna
1 Replies

7. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

8. Shell Programming and Scripting

Search multiple patterns in multiple files

Hi, I have to write one script that has to search a list of numbers in certain zipped files. For eg. one file file1.txt contains the numbers. File1.txt contains 5,00,000 numbers and I have to search each number in zipped files(The number of zipped files are around 1000 each file is 5 MB) I have... (10 Replies)
Discussion started by: vsachan
10 Replies

9. Shell Programming and Scripting

Multiple search string in multiple files using awk

Hi, filenames: contains name of list of files to search in. placelist contains the names of places to be searched in all files in "filenames" for i in $(<filenames) do egrep -f placelist $i if ] then echo $i fi done >> outputfile Output i am getting: (0 Replies)
Discussion started by: pinnacle
0 Replies

10. Shell Programming and Scripting

Multiple search in multiple files

Hello, I would like to perform a search of several different strings in different files. I have the ouput of a unix command X which is for instance: aaa bbb ccc and I would like to look for each of these three strings into several files: file1 file2 etc. I have come up with a solution... (2 Replies)
Discussion started by: maxvirrozeito
2 Replies
Login or Register to Ask a Question