How to use linux grep command? [duplicate] - linux

This question already has answers here:
How do you grep a file and get the next 5 lines
(3 answers)
Closed 6 years ago.
I can only grep and display a particular line of a log file.
What if I want to display the next line together?
Many thanks in advance.

cat filelogname | grep keyword
example : cat /var/log/httpd/error.log |grep Hello

Related

grep command; Display all lines of the file /etc/ssh/sshd_config starting with a letter [duplicate]

This question already has answers here:
How to grep for case insensitive string in a file?
(3 answers)
grep lines that start with a specific string
(2 answers)
How to use the grep with globs patterns? (like we use it in find command)
(2 answers)
Regex to match only letters
(20 answers)
Closed 6 days ago.
Display all lines of the file /etc/ssh/sshd_config starting with a letter.
include capital letters as well
below is what i tried
#!/bin/bash
grep -i 'n*' /etc/ssh/sshd_config
Like this:
grep '^[[:alpha:]]' /etc/ssh/sshd_config

Using grep number as variable is not working [duplicate]

This question already has answers here:
Command not found error in Bash variable assignment
(5 answers)
How do I set a variable to the output of a command in Bash?
(15 answers)
Closed 6 months ago.
I want to grep a number of file in the current directory on linux.
E = $( grep -F "TOTEN" OUTCAR | tail -1 | awk '{printf "%12.9f \n",$5}')
When I run the script, it keeps telling me the command is not found.
I tried many ways to solve it by searching online but it did't work.

insert underscore in columns of a text file shell [duplicate]

This question already has answers here:
Replace whitespace with a comma in a text file in Linux
(9 answers)
Closed 6 years ago.
I have a tab separated text file f.txt like :
APPLE 10 5
BALL 20 6
CAT 30 7
I want the output to be
APPLE_10_5
BALL_20_6
CAT_30_7
I wrote the following to partially accomplish this, but I am stuck at the "paste" step. Can you help?
cat f.txt | cut -f 1,2,3 | paste ???
When the are sperated by one space using sed is a one liner.
sed -i "s/ /_/" input.txt

How to tail all lines except first row [duplicate]

This question already has answers here:
how to read file from line x to the end of a file in bash
(7 answers)
Closed 7 years ago.
For example, I have a file
1
2
3
then I want to output from 2nd row to tail
How can I do it in linux
tail -n+2 my_file
will output all the lines in myfile starting with line 2. (-n2 would show you the last two lines.)
tail has lots more options. Type man tail for complete documentation.
shorter with
$ sed 1d filename
or with awk
$ awk 'NR>1' filename

How to avoid the display of the 2 first line from a linux command output? [duplicate]

This question already has answers here:
What's the opposite of head? I want all but the first N lines of a file
(9 answers)
Closed 8 years ago.
I have a program that displays many line in the output
How I can make it display the all output except the first 2 lines?
easily using tail command:
tail -n+3
You could use awk
awk 'NR>2' file
In order to complete the triplet,
sed '1,2d' file

Resources