Access the word in the file with SSH command - regex

I have a conf file and I use GREP to access the data in this file but not a very useful method for me.
How can I just get the main word?
I using:
grep "HelloWorld" /etc/VDdatas.conf
Print:
export: HelloWorld
I want: (without "export: ")
HelloWorld
How can I do that?

Try the -o or --only-matching option, if you're using gnu grep. It shows only the parts of each line that match..
grep -o "HelloWorld" /etc/VDdatas.conf

Related

Glob files except that including some expression

I want to write a command to build FooMain.cc among the following files:
$ ls src
FooMain.cc
FooMain2.cc
BarMain.cc
Helper.cc
Helper.h
FileToInclude.cc
FileToInclude.h
...
Each main file (those including Main) has main() function and they require all the other files without Main in filenames.
The straightforward way to build would be like:
clang++ [options] FooMain.cc Helper.cc FileToInclude.cc ...
Here the expression HelperOne.cc FileToInclude.cc ... includes all the files but those including Main.
What I want to do is rephrase this expression with glob expression
clang++ [options] FooMain.cc [Some clever glob expression]
I looked up for a while but could not find similar questions.
Appreciate any clues. Thank you!
Using ksh93, bash with the extglob option turned on (shopt -s extglob), or zsh with the ksh_glob option turned on (setopt ksh_glob):
$ clang++ [options] FooMain.cc !(*Main*).cc
Using zsh with the extended_glob option turned on (setopt extended_glob):
$ clang++ [options] FooMain.cc *.cc~*Main*

Pass a regex pattern to Perl Packer from Powershell

How do I correctly write this in a Windows Powershell? Coming from macOS, I have some problems in understanding what it is wrong with this:
pp -u -g -o Executable -f Bleach="^(AAA_|BBB_|MainScript)" MainScript.pl
The regular expression to be passed to the option -f (filter) is not accepted and fires all sort of errors (command not recognized, and so on, no matter as I try to change it). On a Unix system it works just fine.
Escape character for Powershell is `.
Something like this could work:
pp -u -g -o Executable -f Bleach=`"`(AAA_`|BBB_`|MainScript`)`" MainScript.pl`

**/*.java not working as argument to Bash script

I have a simple bash script file named: test.sh.
#!/bin/bash
ls $1;
I gave the execution permissions:
$ ./test.sh "**/*.java"
shows only one file
where as
$ ls **/*.java
shows hundreds of files
So how to make the script work.
To enable support for ** in Bash, use the globstar option:
#!/bin/bash
shopt -s globstar
ls $1
(See ยง4.3.2 "The Shopt Builtin" in the Bash Reference Manual.)

How to grep for a string that includes "->"

I am looking for the literal string ->foo in all the *.cpp files in a single directory. If I try
grep -F "->foo" *.cpp
grep reports
Invalid option -- '>'
Then, if I try
grep -F "-\>foo" *.cpp
I get
Invalid option -- '\'
How can I get this working?
Generally (not grep specific) using -- signifies the end of options:
grep -F -- "->foo" *.cpp
Helpful when you accidentally create files starting with -:
$ touch -- -damn
$ ls -- -*
-damn
$ rm -damn
rm: invalid option -- 'd'
$ rm -- -damn
Try this:
grep -e "->foo" *.cpp
From the man page:
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). (-e is specified by POSIX .) [emphasis added]

Getting gdb to automatically load binary from core file

Can I get gdb to automatically load the binary that's specified in the core file?
Given a core file I now usually do:
gdb -c corefile
GNU gdb 6.8
...
Core was generated by `/path/to/binary'
Then i copy-paste that and run:
gdb -c corefile /path/to/binary
It seems like an unnecessary two-step process and yet I don't seen an obvious way of doing it based on the man page. Am I missing something?
You could just script it?
#!/bin/bash
gdb "`file "$1" | awk -F \' '{print $2}'`" "$1"
This is what I usually endup doing:
var=$(file corefile)
echo ${var##*from}
gdc() {
gdb -c "$1" "$(file "$1" | sed -r -e "s#.*execfn: '([^\']+)'.*#\1#")"
}
$ gdc corefile