Symbols on the end of a line - symbols

is it possible to remove these symbols, and if it is, how am I goding to do that?
Thanks in advance!

Window | Preferences | General | Editors | Text Editors --> Show
whitespace characters

Or perhaps:
$ dos2unix file.java
or
$ unix2dos file.java

Related

grep football player names with special characters

Sorry for asking so many questions recently.
I have another issues with grep in bash. (I am using gitbash)
When I try to use grep for names with special characters e.g.:
Nikola Boranijaševi
Niclas Füllkrug
Christian Groß
Anderson Gonçalves
Oliver Kahn
Manual Neuer
etc....
code I tested:
egrep -i "Nikola Boranijaševi|Niclas Füllkrug|Christian Groß|Anderson Gonçalves" playerlist.csv >>matches.csv
this returns nothing.
the same code works for players without any special characters.....
I even did a small test like:
egrep -aoi "Anderson Gonçalves" playerlist.csv >> matches.csv
but again this did not output anything
does anyone know how to use grep with special characters?
I read here on the forum I should use double \ before special characters so I tried the following to:
egrep -aoi "Anderson Gon\\çalves" playerlist.csv >> matches.csv
again no output... any ideas would be appreciated thanks!!
even a grep with a wildchard chaarcter replacement instead of ç in Anderson Gonçalves in grep would help.. thank you!!
The answer is use wild cards; it's not perfect, but it does work:
egrep -aoi "Nikola Boranija*|Niclas F*|Christian Gro*|Anderson Gon*" playerlist.csv >>matches.csv

Grep match only before ":"

Hello How can I grep only match before : mark?
If I run grep test1 file, it shows all three lines.
test1:x:29688:test1,test2
test2:x:22611:test1
test3:x:25163:test1,test3
But I would like to get an output test1:x:29688:test1,test2
I would appreciate any advice.
If the desired lines always start with test1 then you can do:
grep '^test1' file
If it's always followed by : but not the other (potential) matches then you can include it as part of the pattern:
grep 'test1:' file
As your data is in row, columns delimited by a character, you may consider awk:
awk -F: '$1 == "test1"' file
I think that you just need to add “:” after “test1”, see an example:
grep “test1:” file

Grep's word boundaries include spaces?

I tried to use grep to search for lines containing the word "bead" using "\b" but it doesn't find the lines containing the word "bead" separated by space. I tried this script:
cat in.txt | grep -i "\bbead\b" > out.txt
I get results like
BEAD-air.JPG
Bead, 3 sided MET DP110317.jpg
Bead. -2819 (FindID 10143).jpg
Bead(Gem), Artefacts of Phu Hoa site(Dong Nai province).jpg
Romano-British pendant amulet (bead) (FindID 241983).jpg
But I don't get the results like
Bead fun.jpg
Instead of getting some 2,000 lines, I'm only getting 92 lines
My OS is Windows 10 - 64 bit but I'm using grep 2.5.4 from the GnuWin32 package.
I've also tried the MSYS2, which includes grep 3.0 but it does the same thing.
And then, how can I search for words separated by space?
LATER EDIT:
It looks like grep has problems with big files. My input file is 2.4 GB in size. With smaller files, it works - I reported the bug here: https://sourceforge.net/p/getgnuwin32/discussion/554300/thread/03a84e6b/
Try this,
cat in.txt | grep -wi "bead"
-w provides you a whole word search
What you are doing normally should work but there are ways of setting what is and is not considered a word boundary. Rather than worry about it please try this instead:
cat in.txt | grep -iP "\bbead(\b|\s)" > out.txt
The P option adds in Perl regular expression power and the \s matches any sort of space character. The Or Bar | separates options within the parens ( )
While you are waiting for grep to be fixed you could use another tool if it is available to you. E.g.
perl -lane 'print if (m/\bbead\b/i);' in.txt > out.txt

How to take a particular data using GREP?

Command:
grep -oP '(?<=\"name\":\")[^"]*|(?<=\"title\":\")[^"]*' *.json >newjson
o/p getting as,
10XANY10G_1.json:chMax
10XANY10G_1.json:Max Frequency in GHz
10XANY10G_1.json:up
10XANY10G_1.json:UP
10XANY10G_1.json:down
10XANY10G_1.json:DOWN
10XANY10G_1.json:CapabilityList
10XANY10G_1.json:Capabilities
10XANY10G_1.json:encoding
10XANY10G_1.json:Encoding
expected o/p:
chMax:"Max Frequency in GHz",
up:"UP",
down:"DOWN",
contents of file:
{"card":{"cardName":"10AN10G","portSignalRates":["10AN10G-1-OTU2","10AN10G-1-OTU2E","10AN10G-1-TENGIGE","10AN10G-1-STM64"],"listOfPort":{"10AN10G-1-OTU2":{"portAid":"10AN10G-1-OTU2","signalType":"OTU2","tabNames":["PortDetails"],"requestType":{"PortDetails":"PTP"},"paramDetailsMap":{"PortDetails":[{"type":"dijit.form.TextBox","name":"signalType","title":"Signal Rate","id":"","options":[],"label":"","value":"OTU2","checked":"","enabled":"false","selected":""},{"type":"dijit.form.TextBox","name":"userLabel","title":"Description","id":"","options":[],"label":"","value":"","checked":"","enabled":"true","selected":""},{"type":"dijit.form.Select","name":"Frequency","title":"Transmit Frequency",}}}}}}
I think you're looking for this,
$ grep -oP '(?<=\"name\":\")[^"]*|(?<=\"title\":)[^,]*' file
signalType
"Signal Rate"
userLabel
"Description"
Frequency
"Transmit Frequency"
To get the desired output
$ grep -oP '(?<=\"name\":\")[^"]*|(?<=\"title\":)[^,]*' file | paste -d: - -
signalType:"Signal Rate"
userLabel:"Description"
Frequency:"Transmit Frequency"
I think that your problem is that you are ORing the two groups with | try removing the | and you will get closer to what you are looking for but you may have to add a term to skip any intervening tags for cases where name and title are not immediately after each other, then you might have to get clever to deal with the case that has an entry with a name but no title.
As said grep is not the best tool for parsing json there are numerous others - personally I would suggest using python and the json library to load your file then output the tags that you need.
Here is an gnu awk (due to RS) version to extract data:
awk -F\" '/title/ {print $3":"$7}' RS='name' file
signalType:Signal Rate
userLabel:Description
Frequency:Transmit Frequency

How can I know how many times a word is in a file using grep?

I have a file and I want to know how many times does a word is inside that file.(NOTE: A row can have the same word)
You can use this command. Hope this wil help you.
grep -o yourWord file | wc -l
Use the grep -c option to count the number of occurences of a search pattern.
grep -c searchString file
awk solution:
awk '{s+=gsub(/word/,"&")}END{print s}' file
test:
kent$ cat f
word word word
word
word word word
kent$ awk '{s+=gsub(/word/,"&")}END{print s}' f
7
you may want to add word boundary if you want to match an exact word.
Yes, i know you want a grep solution, but my favorite perl with the rolex operator can't missing here... ;)
perl -0777 -nlE 'say $n=()=m/\bYourWord\b/g' filename
# ^^^^^^^^
if yoy want match the YourWord surrounded with another letters like abcYourWordXYZ, use
perl -0777 -nlE 'say $n=()=m/YourWord/g' filename

Resources