Hey. I want to know whether i can compare two files line by line and print matching lines to a new file. I have tried using foreach loop. But didn't work. If possible let me know how i can do this using foreach loop. Thanks
@@PedagogyV No. That doesn't work. Comm - 12 works for small strings. Not for entire lines. The content in 2 files that I'm comparing is like this. /shsvbs/clkc-r4738-sbs/sguahvs-refy_jegbsk/. Only bigger. Each and every line in file1 is unique and has around 1000 lines. Same for the file2 as well. But some lines in both files match. So comm - 12 doesn't do at all. Have to use foreach or some other loop to compare 2 files line by line and output the matching lines to a 3rd file.
@@boggarapulokesh3224 Not sure why it is not working in your case. If possible , could you pls send these two file in telegram group, so that I can look into the problem and provide you some solution.
for any set of lines you can use first sed command. ex :- sed -n '2,12p' filename : it will print line 2 to line 12 of file . after that use grep within this range , i.e sed -n '2,12p' file | grep word :- it will grep within this range of line and print them . now , if you want to send the output to a file instead of printing , use redirect i.e sed -n '2,12p' file | grep word > file2 :- it will redirect output to the file instead of printing. hope , this will help :) Not sure , why youtube is marking line over some of my comment , but take it as no line is marked on any comment.
@@PedagogyV I have 1 file in which I have to perform grep -v "pattern" 3 4 times So I want to do via script. It's like if I source in outcomes without performing grep 3 4 times.
@@Yogeshkumar-dc2cr you can use shell scripts and loop 3.. 4 time .. create an array first with index values like arr=("pattern1" "pattern2" "pattern3") for a in ${arr[@]} do grep -v ${a} dafile done in case it didn't work , please explain in telegram group
If two words are in same sentence its would be display only those sentence and I want to know if we can search two words at a time in file that should display the only sentence For eg:- What is your name? My name is Ram Ram is my name Ram what are you doing Question :- search ram and name and display only those sentence. Not all containing single words. Output :- My name is Ram Ram is my name