Sponsored Content
Top Forums Shell Programming and Scripting Need to build Shell Script to search content of a text file into a folder consist several files Post 302555920 by ctsgnb on Friday 16th of September 2011 06:07:16 AM
Old 09-16-2011
Code:
$ cat f1
toto
titi

Code:
$ cat f2
jfdklsjfkldsq
jfdklsjfkldsq
toto
jfdklsjfkldsq
toto titi toto titi
jfdklsjfkldsq
titi
jfdklsjfkldsq

Code:
$ cat f3
toto
jfdklsjfkldsq
toto titi toto titi
jfdklsjfkldsq
titi

Code:
$ nawk 'NR==FNR{a[++c]=$0;next}{for(i in a) {if (match($0,a[i])) print FILENAME,a[i],FNR };next}' f1 f2 f3
f2 toto 3
f2 toto 5
f2 titi 5
f2 titi 7
f3 toto 1
f3 toto 3
f3 titi 3
f3 titi 5

also
Code:
$ nawk 'NR==FNR{a[++c]=$0;next}{d=1;do{if (match($0,a[d])) print FILENAME,a[d],FNR}while(++d in a);next}' f1 f2 f3
f2 toto 3
f2 toto 5
f2 titi 5
f2 titi 7
f3 toto 1
f3 toto 3
f3 titi 3
f3 titi 5


Last edited by ctsgnb; 09-16-2011 at 07:23 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to search content of file with timestamps in the directory

hello, i want to make a script to search the file contents in my home directory by a given date and output me the line that has the date... (10 Replies)
Discussion started by: psychobeauty
10 Replies

2. Shell Programming and Scripting

shell script to search a string and delete the content

Hi, I've a shell script e.g. #!/bin/bash echo "Enter the next hop id" read nhid echo "enter the IP address" read IP echo "enter the interface name" read name echo "enter the enable/disable state" read state exit 0 now from this script i want to search strings in another (.cam) ... (6 Replies)
Discussion started by: vic_mnnit
6 Replies

3. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

4. Shell Programming and Scripting

write shell script to search file in folder

hi .. i have a problem how to search file with date and version number(ms_2.0_dd/mm/yy_24)in folder.Here 24 is version number and compare the this file to other file which is in another folder and if does not match then copy this file to respective folder.Also copy different files in different... (1 Reply)
Discussion started by: shubhig15
1 Replies

5. Shell Programming and Scripting

Reading files under a folder and formatting content of each file

I have 'n' number of files in a folder .each file in the folder "myfolder" is having the content like. COLNAME ------------ AAAAAA BBBBBB CCCCCC DDDDDD ... ... ... ZZZZZZ 26 recrod(s) selected. My request is by reading each file in "myfolder" and format each file such a way... (18 Replies)
Discussion started by: rocking77
18 Replies

6. Shell Programming and Scripting

Script to create a text file whose content is the text of another files

Hello everyone, I work under Ubuntu 11.10 (c-shell) I need a script to create a new text file whose content is the text of another text files that are in the directory $DIRMAIL at this moment. I will show you an example: - On the one hand, there is a directory $DIRMAIL where there are... (1 Reply)
Discussion started by: tenteyu
1 Replies

7. Shell Programming and Scripting

search for content in files. Name of files is in another file. Format as report.

Hi I have multiple files in a folder and one file which contains a list of files (one on each line). I was to search for a string only within these files and not the whole folder. I need the output to be in the form File1<tab>string instance 2<tab> string instance 2<tab>string instance 3... (6 Replies)
Discussion started by: pkabali
6 Replies

8. Shell Programming and Scripting

How to create a shell script to read a foldername from a text file and go to the folder?

Hi, I am trying to write a shell script which can read folder names from a text file and then go to the folder and picks up a xml file and write on my sipp script so that I can run the sipp script. For example: I have a text file called thelist.txt where I have provided all the folders... (7 Replies)
Discussion started by: pm1504
7 Replies

9. UNIX for Dummies Questions & Answers

How to sort a content of a text file using a shell script?

I am new to shell scripting. I am interested how to know how to sort a content of a file using shell scripting. I've attached the 'Input file' and the 'expected output' to this thread. Details provided in the expected output file will provide details on how the sort needs to be done. ... (16 Replies)
Discussion started by: nkarthik_mnnit
16 Replies

10. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies
DIETTESTTOOL(1) 														   DIETTESTTOOL(1)

NAME
DIETTestTool - Example of a tool for DIET using the LogCentral NAME
DIETTestTool - Example of a tool that connects to the LogCentral without any filter and that display all the messages published. It is used as an example for the DIET program. All received published messages are also stored in a log file. SYNOPSYS
DIETTestTool [options] ... DESCRIPTION
DIETTestTool connects to the LogCentral and get the messages (by default all, a file containing filters may be passed as an argument). The tool both display and save the messages in a log file. This log file may be given or will be created with a fix name "DIETLogTool.log". Before starting the LogCentral, you must: o launch a CORBA Naming Service. o launch log forwarders if needed o launch LogCentral service o Launch the DIETTestTool o Use a component to publish messages OPTIONS
o The first argument is the destination output file that will contain the displayed logs. o The second one is a filter to use in the tool [Remark: There is no option letter, the order is fixed] EXAMPLE
o Launching the LogCentral LogCentral -config ./LogCentral.cfg o Launching the tool DIETTestTool o Launching the tool to store the logs in the toto.log file DIETTestTool toto.log o Launching the tool to store the logs in the toto.log file with the filter in the filter.txt file DIETTestTool toto.log filter.txt RATIONALE
The LogTool uses CORBA as its communication layer. While it's a flexible and robust middleware, its deployement on heterogeneous networks still is delicate and may require using ssh tunnels. LICENSE AND COPYRIGHT
Copyright (C)2011, GRAAL, INRIA Rhone-Alpes, 46 allee d'Italie, 69364 Lyon cedex 07, France all right reserved <diet-dev@ens-lyon.fr> License This program is free software: you can redistribute it and/or mod- ify it under the terms of the GNU General Public License as pub- lished by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Pub- lic Li- cense for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. AUTHORS
GRAAL INRIA Rhone-Alpes 46 allee d'Italie 69364 Lyon cedex 07, FRANCE Email: <diet-dev@ens-lyon.fr> WWW: http://graal.ens-lyon.fr/DIET SEE ALSO
omniNames(1), logForwarder(1), LogCentral(1), testComponent(1) BUGS
AUTHOR
haikel.guemar@sysfera.com, kevin.coulomb@sysfera.com License: GPLv3 COPYRIGHT
DIET developers 0.1 2011-05-16 DIETTESTTOOL(1)
All times are GMT -4. The time now is 03:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy