0

I have a file that has about 63000 row I need to grep though

[root@server]# cat missinglinks.txt
69870  1.pdf.Published
125098 2.png.Published
125022 3.pdf.Published
69867  4.png.Published

I have a list of 450 numbers that will match some of the row in the missinglinks.txt file

[root@server]# cat missinglinksA.sh
125105
125104
125103
125102
125100
125099
125098
125097
125022

I am trying to use a script to take the first row from missinglinksA.sh and grep missinglinks.txt and output to a file, then the second, n.....

for n in $(cat missinglinksA.txt)
do
    cat missinglinks.txt | grep $n
done

I would like an output file like:

[root@server]# cat missinglinksAout.txt
125098 2.png.Published
125022 3.pdf.Published

I cannot however get the output either on the screen or to a text file, I am not sure if I am doing something wrong or if the script is simply not outputing.

I have -o -i none seem to fix the issue.

I can do:

[root@server]# cat missinglinksA.txt | grep 125098 >> missinglinksAout.txt

And it works.

[root@server]# cat missinglinksAout.txt
125098 2.png.Published

I have taken the top 10 rows from the missinglinksA.txt file and made a script to check each line and that does not work either, blank output.

[root@server]# cat missinglinksAtesteachline.sh
cat missinglinksA.txt | grep 125105
cat missinglinksA.txt | grep 125104
cat missinglinksA.txt | grep 125103
cat missinglinksA.txt | grep 125102
cat missinglinksA.txt | grep 125100
cat missinglinksA.txt | grep 125099
cat missinglinksA.txt | grep 125098
cat missinglinksA.txt | grep 125097
cat missinglinksA.txt | grep 125022

[root@server]# sh missinglinksAtesteachline.sh
[root@server]#
Andrew Sitterly
  • 300
  • 2
  • 9
  • 1
    I think you'll have an easier time solving this if you use some quotes and maybe "grep --color=never" just to minimize confusion. – Jed Daniels Feb 10 '20 at 18:08
  • maybe fgrep is better on huge files ; you can olso prefer to use -F & -f to optimize the search. another way is to `while read -r line ; do ; grep pattern $line >> /tmp/output_result.$(date +%Y%m%d).txt ; done < inputfile` You can also search on the stackexhange "read huge file" maybe to get more methods and find the best for your needs. – francois P Feb 10 '20 at 18:11

1 Answers1

0

Taking the copies from your "cats", i can use yield the expected results with the following command:

$ fgrep -f missingLinksA.txt missingLinks.txt 
125098 2.png.Published
125022 3.pdf.Published

I hope this helps.

womble
  • 96,255
  • 29
  • 175
  • 230
kiwo
  • 16