How do i get the output on the right? when my answers on the left is wrong? - centos7

it wants the answers for getting only the .txt files with the word "grep" with the grep commands the picture on the left shows answers ive tried and the picture on the right is the question.

Related

Need help in ignoring certain lines when reading a file so that I don't have to include them in the calculations using VScode

Okay, so I am writing a program that reads a file and prints all the lines in it. I don't want it to print lines that start with # and + and print all the other lines.
The code that I have written looks like this Code
The output looks like the following Output. So I want the output to print only those lines without starting with + and #.
I have stuck with this problem for a while and will really appreciate it if anyone can provide any hints as to what to do?
Thanks in Advance
Sorry I couldn't format the right coding style on stack overflow because I'm new but if you need help in understanding it don't hesitate to ask me
Regards,
Abdul Hadi

How combine regex and find in shell script properly

I am trying to write a shell script which can take numbers from a text document and use these numbers to search for all pictures that include the numbers in their name.
I am working with find and it I got it to kinda work. If the name of the picture is exactly the same as the name in the text document, or if the name of the picture ends with whatever number is written in the text document it works. But if the number is in the middle of the name of the picture, it doesn't find it. So I have been trying to add regex to my find command but I haven't been successful.
input="/Users/unix/Desktop/pictures.txt"
input_2="/Users/unix/Desktop/2019/05/23"
while IFS= read -r -u3 line
do
find "$input_2" -iregex ".*${line}*.jpg"
done 3< "$input"
For example if the picture name is Right.jpg and my pictures.txt contains Right, it will find the file. If the picture is called leftRight.jpg, it will also find the File. But if it's something like leftRightleft.jpg, it won't find the picture, so I am a bit confused on how to use regex properly here.
Your regex is simply incorrect. If you break it down, it makes intuitive sense why:
.*${line}*.jpg
means:
.* -- any character repeated 0 or more times
${line}* -- the contents of ${line}, with the last character repeated 0 or more times
. -- any single character
jpg -- the literal characters jpg
So with your example, if you have Right in your file, you'd match actual files like these, which you probably don't want to match:
leftRigh.jpg
leftRighXjpg
leftRighttttttttt.jpg
leftRighttttttttttttttttttttttttttttttttjpg
What you probably want is:
.*${line}.*\.jpg

How to find and replace box character in text file?

I have a large text file that I'm going to be working with programmatically but have run into problems with a special character strewn throughout the file. The file is way too large to scan it looking for specific characters. Most of the other unwanted special characters I've been able to get rid of using some regex pattern. But there is a box character, similar to "□". When I tried to copy the character from the actual text file and past it here I get "�", so the example of the box is from Windows character map which includes the code 'U+25A1', which I'm not sure how to interpret or if it's something I could use for a regex search.
Would anyone know how I could search for the box symbol similar to "□" in a UTF-8 encoded file?
EDIT:
Here is an example from the text file:
"� Prune palms when flower spathes show, or delay pruning until after the palm has finished flowering, to prevent infestation of palm flower caterpillars. Leave the top five rows."
The only problem is that, as mentioned in the original post, the square gets converted into a diamond question mark.
It's unclear where and how you are searching, although you could use the hex equivalent:
\x{25A1}
Example:
https://regex101.com/r/b84oBs/1
The black diamond with a question mark is not a character, per se. It is what a browser spits out at you when you give it unrecognizable bytes.
Find out where that data is coming from.
Determine its encoding. (Usually UTF-8, but might be something else.)
Be sure the browser is configured to display that encoding. This is likely to suffice <meta charset=UTF-8> in the header of the page.
I found a workaround using Notepad++ and this website. It's still not clear what encoding system the square is originally from, but when I post it into the query field in the website above or into the Notepad++ Conversion Table (Plugins > Converter > Conversion Table) it gives the hex-character code for the "Replacement Character" which is the diamond with the question mark.
Using this code in a regex expression, \x{FFFD}, within Notepad++ search gave me all the squares, although recognizing them as the Replacement Character.

Need help trying to undo a VIM mistake [duplicate]

This question already has answers here:
How do you make Vim unhighlight what you searched for? [duplicate]
(14 answers)
Closed 6 years ago.
So I'm practicing Ruby on Codeacademy and to save the work that I'm doing I copied and pasted my code onto my cmd prompt using VIM. However, I noticed that each line of code was commented with the '#' symbol and I wanted to remove them.
To be productive, I searched online how to use regex to search for all the hashtags and remove them with this command:
:%s/#//gc
Then this popped up:
replace with (y/n/a/q/l/^E/^Y)?
I pressed y every time until the message disappeared and now I'm stuck with all hashtags characters being replaced with a yellow rectangle. So instead of having this:
#
I have this:
[] but shaded in yellow for every time I use a hastag.
Any help would be much appreciated!
The yellow rectangle represents the characters that matched your expression. To clear the last search highlighting, use:
:noh
To uncomment the lines of code, I would just do this:
Use V to select each line, then
:norm x

Vb.Net Scraped Data MsgBox Shows Line Breaks but RichTextBox Does Not [duplicate]

This question already has answers here:
Write in new line in rich text box. with vb
(5 answers)
Closed 7 years ago.
So I'm scraping data and I've got my xpath parsing out the line I need.
I go line by line and dump out the data so I know I'm looking in the right place and for every listing it's showing several lines which is good. Exactly what I expected.
Example Msgbox dump:
Msgbox(node.innertext)
Example Msgbox Outputs:
Mr C Moore
10/2
5/1
17/6
Hit OK and the next one comes up:
M D Hunt
1/1
3/1
12/500
And it continues like that for every listing. Great.
I try to split it by environment.newline and get - nothing. Everything is on splitarray(0) so I dump the innertext into a rich text box and everything is squashed up.
Example rich text box dump:
rtbdump.text = node.innertext & environment.newline & rtbdump.text
Example Rich text box output:
Mr C Moore10/25/117/6
M D Hunt1/13/112/500
I need to be able to work with these lines individually. The Msgbox output was clearly able to do that but writing it to a rich text box was all squashed together and splitting by environment.newline doesn't work.
With regex I was able to split the names out - that's a start. But I can't get any further since the numbers have no set pattern or length.
Would appreciate anyone who can point me in the right direction.
I have no idea why this is a thing but apparently splitting by 'vbLf' is different from environment.newline and solved my problem.