![]() Please let me know if there are any other ways to get this done through the shell script. I need a generalized solution for all cases. I don't know how I can do that when file1 is being compared with multiple files in a continuous manner. that (a) contain the string "/abc/bce/12345/input/part3" + an added string (the filenames), but (b) don't contain the other "/abc/bce/12345/input/part3/err" string. But I want to get lines in file2.txt, file3.txt. When it finds a pattern that matches in more than one file, it prints the name of the file. However the problem lies, when I take the 1st line from file1 and try to retrieve the path+File_name, it takes all the similar lines from file2,file3, and so on. The grep command can search for a string in groups of files. I am using grep -rHw "/abc/bce/12345/input/part3" test/ to match the line from file1 and extract their info from file2,file3. ![]() Test/file2.txt:/abc/bce/12345/input/part3/AIR9923.txt-20210315- 2 Answers Sorted by: 3 You can add the -w command line option to restrict the match to whole words printf 'rs123456 rs246 ' grep -wE 'rs123rs246rs689653' rs246 or add word-anchors explicitly printf 'rs123456 rs246 ' grep -E '\b (rs123rs246rs689653)\b' rs246 (you were close with and - but those are line -anchors). Note that when -count is combined with -only-matching, then ripgrep behaves as if -count-matches. Present output: test/file2.txt:/abc/bce/12345/input/part3/AIR9905.txt-20210421- The file can specify one shell argument per line. and this could work also on a column different from the first (just use 2 for second column, 3 for the third, and so on). you can write something like this: awk 1 'STRINGTOMATCH' txtfile.txt. abc/bce/11198/input/VII/part3/err/V.AIR7650.txt-20170625- When you need matching on a specific field (or column) of your files, it could be better to use a tool like awk instead of grep. abc/bce/12345/input/part3/err/AIR1034.txt-20210110- Sadly some of the regex patterns cannot be limited any further, so. install the GNU grep on your Solaris box (it might already be installed in /usr/sfw/bin, or you might have luck with pkg install //solaris/text/gnu-grep ) or. Solaris version of grep does not have the -o option. ![]() abc/bce/12345/input/part3/AIR9905.txt-20210421- I am assuming this is a Solaris box you are connecting to. ![]() I have multiple files(text file) in a folder like below where the 1st file contains some paths as a string and the other with path+file_name. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |