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

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

Related

Shell script make lines in one huge file into two seperate files in one go? [duplicate]

This question already has answers here:
How to save both matching and non-matching from grep
(3 answers)
Closed 1 year ago.
Currently My shell script iterate the lines in one huge file two times:
(What I want to do is just like the shell script below.)
grep 'some_text' huge_file.txt > lines_contains_a.txt
grep -v 'some_text' huge_file.txt > lines_not_contains_a.txt
but it is slow.
How to do the same thing only iterate the lines once?
Thanks!
With GNU awk:
awk '/some_text/ { print >> "lines_contains_a.txt" }
!/some_text/ { print >> "lines_not_contains_a.txt" }' huge_file.txt
With sed:
sed -n '/some_text/ w lines_contains_a.txt
/some_text/! w lines_not_contains_a.txt' huge_file.txt

How to use linux grep command? [duplicate]

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

How to delete last found value in Bash [duplicate]

This question already has answers here:
Bash : extracting part of a string
(4 answers)
Closed 6 years ago.
Say I have a string 0.0.25, how do I delete the last part after dot (including it) to make it like 0.0? Note that last part can have variable number of digits.
In bash you can do the following:
echo "${var%.*}"
See the Shell Parameter Expansion section of the manual.
Using awk you could:
echo "0.0.25" | awk -F. '{print $1"."$2}'

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

Why is SED echoing rather than editing: sed '/^;text1/!b;:a;n;//ba;i\text2' [duplicate]

This question already has answers here:
How do I use a new-line replacement in a BSD sed?
(4 answers)
Closed 7 years ago.
sed '/^;date.timezone =/!b;:a;n;//ba;i\date.timezone = Europe/London' /etc/php.ini
You can probably guess Im creating a script for setting up LAMP servers.
In the above example the text is not replaced but instead the changes are displayed on the console.
I my goal was to insert date.timezone = Europe/London the last occurence of ;date.timezone =
Etan Reisner:
You aren't using the -i flag to tell sed to modify in place.

Resources