If the tabulated lines are the ones that have a tab character:
grep '␉' <input_file >output_file
(␉
being a literal tab character) or equivalently
sed -n '/␉/p' <input_file >output_file
In a bash/ksh/zsh script, you can write $'\t'
for a tab, e.g. grep $'\t'
or sed -n $'/\t/p'
.
If you want to eliminate 10 lines at the beginning of the file:
tail -n +11 <input_file >output_file
(note that it's +11
to eliminate 10 lines, because +11
means “start from line 11” and tail numbers lines from 1) or
sed '1,10d' <input_file >output_file
On Linux, you can take advantage of GNU sed's -i
option to modify files in place:
sed -i -n '/\t/p' *.txt
Or you can use a shell loop and temporary files:
for x in *.txt; do
tail -n +11 <"$x" >"$x.tmp"
mv "$x.tmp" "$x"
done
Or if you don't want to modify the files in place, but instead give them a different name:
for x in *.txt; do
tail -n +11 <"$x" >"${x%.txt}.data"
done
sed -i -e 1,3d yourfile
. This won't echo anything, it will just modify the file in-place. If you don't need to pipe the result to another command, this is easier. – Yanick Girouard May 02 '12 at 23:46sed -i
specifically. Most implementations just delete the file and replace it with a new one, which doesn't work for links since you end up leaving the original at its other location. – jw013 Jan 07 '14 at 22:21sed
doesn't do it in-place at all, it creates a temp file. – jfa Nov 26 '16 at 18:24tail
solution, if you're trying to get the last 2 lines you can dotail -n -2 t.txt
. – Joshua Pinter Jul 08 '21 at 15:01