new line separator for each grep result sh script [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there a way to have each result of grep followed by newline
for example if the result of grep is:
1
2
3
I need it to be:
1
2
3

grep "pattern" /path/to/file | awk '{print $0,"\n"}'

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.

How can I print the total number of file descriptors with index 24 [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 8 years ago.
Improve this question
How can I print the total number of file descriptors with index 24 for all the running processes?
I tried something: $
ls /proc/*/fd 2> errors.txt > stdout.txt | grep "^24" stdout.txt | wc -l
This solution returns 0 everytime.
I mention that my task ask me to write an one liner in order to solve it.
ls /proc/*/fd 2>/dev/null | grep -c '^24$'

Shell command to extract string within bracket (String) in a variable like status(running) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am building a AIX bash shell utility whereby i get a dynamic variable with value like status(running).
I just need the string within brakets that is running.
Right now i am able to get the whole word with status along with the brackets using awk print.
Can anyone suggest me how to just extract the running out of it. Thanks.
Let's say:
s='(running)'
Using pure BASH:
echo "${s//[()]/}"
running
Using sed:
echo "$s" | sed 's/[()]//g'
running
Using tr:
tr -d '()' <<< "$s"
running
UPDATE: As per comments by OP:
s='status(running)'
Using sed:
echo "$s" | sed 's/^.*(\(.*\)).*$/\1/g'
running
Using pure BASH:
t="${s#*\(}"
echo "${t%)*}"
running

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/'

Linux using grep command [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
After using grep command, i will give you a small example
grep test
test this is first line : 1
test this is second line : 2
test this is third line : 3
test this is fourth line : 4
How to filter the last line after grep command executed
finally i need the result 4
If I don't misunderstand you:
$grep test | tail -1
>test this is fourth line : 4
$grep test | tail -1 | awk '{print $7}'
>4
$7 is 'the seventh column' in awk.

Resources