Suppress Non-Matching Lines in Grep [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Running service --status-all | grep "firestarter" in Ubuntu shows the entire output of service --status-all with the text "firestarter" highlighted in red. How do you get grep to only show the line that contains the matched text, and hide everything else?

Maybe service --status-all writes to stderr, not stdout? Then you can use
service --status-all 2>&1 | grep firestarter

You must have some weird env variables set. Try this:
service --status-all | `which grep` firestarter
Or:
service --status-all | /bin/grep firestarter
And show the output of env and alias if possible so we can see whats wrong with your grep command.
For me, I have:
[ 13:55 jon#host ~ ]$ echo $GREP_OPTIONS
--color=always
You probably have something set there, and/or in GREP_COLOR that is causing this.

if you don't want to use an alias, but the original command, you could try "\cmd". e.g.
service --status-all | \grep "firestarter"

Related

What does grep -v _1_ <file_name> do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I'm new to bash scripting, can someone tell me what is the meaning of the below command.
grep -v _1_ <file_name> > <new_file>
The -v switch inverts the criteria, so it shows only the lines which does NOT contain the string _1_ and logs the output into the file <new_file>.
The question is wrong, you have written the command as:
grep -v _1_ <file_name> > <new_file>
While it should be:
grep -v _1_ <file1> > <file2>
You can use grep on more file than one, which means that you are looking for something in more than one file.
The -v part is already explained by Antonio.

Parsing a conf file in bash [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Here's my config file
#comment 1
--longoption1
#comment 2
--longoption2
#comment 3
-s
#comment 4
--longoption4
I want to write a bash script that will read this .conf file, skip comments and serialize the commandline options like so.
./binary --longoption1 --longoption2 -s --longoption4
Working off of this post on sed, you just need to pipe the output from sed to xargs:
sed -e 's/#.*$//' -e '/^$/d' inputFile | xargs ./binary
As Wiimm points out, xargs can be finicky with a lot of arguments and it might split it up across multiple calls to binary. It may be better off to use sed directly:
./binary $(sed -e 's/#.*$//' -e '/^$/d' inputFile)

linux/ unix command for checking specific logs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
how can I extract a log based on specific time frame? Let's say issue started between 4pm to 5pm, how can I get that specific log between those times? I can use less or cat or grep but it would not give me the details of the error, sample command:
grep "2013-08-26 16:00:00" sample.log
what is the more precise Linux/ Unix command that can do the trick?
For viewing ERROR log messages between 16:00:00 and 17:00:00 use:
grep -nP '2013-08-15 16:.+ERROR' sample.log | less
If you have multiline messages in log you can use -A n and -B n params to add for each output string n lines after or before:
3 lines before and after each line:
grep -A 3 -B 3 -nP '2013-08-15 16:.+ERROR' sample.log | less
Shorthand for the same:
grep -3 -nP '2013-08-15 16:.+ERROR' sample.log | less
If you know that issue happened between 4 and 5 pm, you can use this:
grep "2013-08-26 16:" sample.log | less
If you need some lines around that issue, add option -N to grep (context of N lines), something like that:
grep -3 "2013-08-26 16:" sample.log | less
If you know that your event contained some specific word, you can filter it more using one more grep:
grep -3 "2013-08-26 16:" sample.log | grep somethingelse

Playing Sound in Putty during tail Option [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
My requirement is to play an alert (Play Sound) in putty if any Exception occurs in the Application , so for this purpose i have tried the below way
tail -f flex.log | grep "Exception" --color paplay alert.wav
But even though the word Exception occurs in flex Log File during tail , but it is not playing the sound .
Please let me know if there is any mistake in the above command .
I am using centOS 8 as OS and script is bash .
This will find all words with Exception and replace it with the bell character, your terminal should beep/flash/whatever you've set up to happen during a terminal bell.
tail -f flex.log | grep "Exception" | sed -e $'s/Exception/Exception\a/'
To see ALL lines of flex.log but bell only on "Exception":
tail -f flex.log | sed -e $'s/Exception/Exception\a/'

new line issue with netcat [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using below command to send some strings to udp listening server.
echo "A 192.168.192.168" | nc -u 192.168.2.1 1234
but the server is getting trailing '\n' in echoed string.
I have tried below command too, but failed
echo "A 192.168.192.168" | nc -uC 192.168.2.1 1234
How can I remove that trailing new line character ??
Do I have any special option in nc ??
echo usually provides -n flag. This is not standard.
string A string to be written to standard output. If the first operand is -n, or if any of the operands contain a backslash ( '\' ) char‐
acter, the results are implementation-defined.
On XSI-conformant systems, if the first operand is -n, it shall be treated as a string, not an option.
I would suggest using printf
printf "A 192.168.192.168" | nc -u 192.168.2.1 1234
printf doesnt append a new line unless it is told to, and it's standard behavior.
Try using
echo -n
so
echo -n "A 192.168.192.168" | nc -u 192.168.2.1 1234
echo man page says: -n do not output the trailing newline

Resources