How do I delete the first n lines of an ascii file using shell commands?Delete first 10 Lines From Multiple FilesRegarding deleting first 327 lines in all the .dat files in a foldergrep -v: How to exclude only the first (or last) N lines that match?How to delete number of lines from file repetitivelyWhat platform to use for programmatically editing text files?Wrap lines to a specified number of fieldsHow to remove Russian and Arabic strings from a text fileCopy the first 2 lines from a file and then remove the linesHow do I delete the last n lines of an ascii file using shell commands?Get lines matching a pattern in one file and put them into a second file matching the same patternBatch sorting multiple files and removing duplicate lines from multiple files - in place if possibleReplace anything between parentheses even if spanning multiple linesText Processing - Get 2 lines with exact text between themmultiple patterns with sed (regex AND or condition)
What is the opposite of 'gravitas'?
How do I go from 300 unfinished/half written blog posts, to published posts?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
How does it work when somebody invests in my business?
Is expanding the research of a group into machine learning as a PhD student risky?
How do we know the LHC results are robust?
Detecting if an element is found inside a container
Where does the Z80 processor start executing from?
How easy is it to start Magic from scratch?
Why Were Madagascar and New Zealand Discovered So Late?
Applicability of Single Responsibility Principle
For a non-Jew, is there a punishment for not observing the 7 Noahide Laws?
How did Doctor Strange see the winning outcome in Avengers: Infinity War?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Opposite of a diet
Purchasing a ticket for someone else in another country?
Sequence of Tenses: Translating the subjunctive
How to check is there any negative term in a large list?
How did Arya survive the stabbing?
Proof of work - lottery approach
Implement the Thanos sorting algorithm
Short story about space worker geeks who zone out by 'listening' to radiation from stars
How do I extract a value from a time formatted value in excel?
Risk of infection at the gym?
How do I delete the first n lines of an ascii file using shell commands?
Delete first 10 Lines From Multiple FilesRegarding deleting first 327 lines in all the .dat files in a foldergrep -v: How to exclude only the first (or last) N lines that match?How to delete number of lines from file repetitivelyWhat platform to use for programmatically editing text files?Wrap lines to a specified number of fieldsHow to remove Russian and Arabic strings from a text fileCopy the first 2 lines from a file and then remove the linesHow do I delete the last n lines of an ascii file using shell commands?Get lines matching a pattern in one file and put them into a second file matching the same patternBatch sorting multiple files and removing duplicate lines from multiple files - in place if possibleReplace anything between parentheses even if spanning multiple linesText Processing - Get 2 lines with exact text between themmultiple patterns with sed (regex AND or condition)
I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information. In a shell script, I want to remove these first few lines of text so that I can use the pure matrix information in another program. How can I use bash shell commands to do this?
If it's any help, I'm using RedHat and an Ubuntu linux systems.
bash shell-script text-processing
add a comment |
I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information. In a shell script, I want to remove these first few lines of text so that I can use the pure matrix information in another program. How can I use bash shell commands to do this?
If it's any help, I'm using RedHat and an Ubuntu linux systems.
bash shell-script text-processing
add a comment |
I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information. In a shell script, I want to remove these first few lines of text so that I can use the pure matrix information in another program. How can I use bash shell commands to do this?
If it's any help, I'm using RedHat and an Ubuntu linux systems.
bash shell-script text-processing
I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information. In a shell script, I want to remove these first few lines of text so that I can use the pure matrix information in another program. How can I use bash shell commands to do this?
If it's any help, I'm using RedHat and an Ubuntu linux systems.
bash shell-script text-processing
bash shell-script text-processing
edited May 3 '12 at 1:07
Gilles
544k12811041621
544k12811041621
asked May 2 '12 at 23:36
PaulPaul
1,99392127
1,99392127
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
As long as the file is not a symlink or hardlink, you can use sed, tail, or awk. Example below.
$ cat t.txt
12
34
56
78
90
sed
$ sed -e '1,3d' < t.txt
78
90
You can also use sed in-place without a temp file: 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.
tail
$ tail -n +4 t.txt
78
90
awk
$ awk 'NR > 3 print ' < t.txt
78
90
8
You can also use sed in-place without a temp file: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 2 '12 at 23:46
1
Thanks @YanickGirouard, @IgnacioVazquezAbrams! You two have just saved me a ton of manual labor on my research! :)
– Paul
Sep 6 '12 at 5:22
2
@Svetlanased -ispecifically. 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 7 '14 at 22:21
4
how about explaining what '1,3d', +4, et.c. means? The question was for n lines, but you didn't tell what n is (as apparently n is 2 in your examples, though it's not obvious for a noob what to change in order to change n)
– Robin Manoli
Feb 1 '15 at 10:29
2
This uses a temp file so not very useful for a 100% util disk space. Would be interesting to have a solution that does this literally "in-place".
– Shai
Sep 2 '16 at 21:09
|
show 5 more comments
sed -i '1,3d' file.txt
This deletes first 3 line from file.txt.
add a comment |
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
2
"tabulated" usually means "pretty-printed in a table", not "indented with tab characters".
– Ignacio Vazquez-Abrams
May 3 '12 at 2:14
@IgnacioVazquez-Abrams I know. The pretty-printed table sometimes uses tab characters, that's easier to spot than aligned columns. Of course, if Paul gave a sample input, I could give a better matcher.
– Gilles
May 3 '12 at 10:04
add a comment |
You can use Vim in Ex mode:
ex -sc '1d5|x' file
1move to first line5select 5 linesddeletexsave and close
add a comment |
echo "anb" | sed '1d' # deletes first line
cat list.txt | sed '1d' > list.csv # read list.txt and write list.csv without first line
Other useful commands:
grep '^|' # finds first character (pipe|)
sed 's/|//g' # deletes pipe
sed 's/ //g' # deletes space
add a comment |
By percentage
Using bash, to clean up a file using a percentage number instead of an absolute number of lines:
sed -i -e 1,$( printf "$((`cat php_errors.log | wc -l` * 75 /100 ))" )d php_errors.log
Watch out because that command can be destructive since it deletes content in-place, without creating a copy.
It deletes the first 75% of lines from the mentioned file.
I am a bash newbie, so I am sure this could be made prettier and faster, and I welcome suggestions to achieve this.
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f37790%2fhow-do-i-delete-the-first-n-lines-of-an-ascii-file-using-shell-commands%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
As long as the file is not a symlink or hardlink, you can use sed, tail, or awk. Example below.
$ cat t.txt
12
34
56
78
90
sed
$ sed -e '1,3d' < t.txt
78
90
You can also use sed in-place without a temp file: 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.
tail
$ tail -n +4 t.txt
78
90
awk
$ awk 'NR > 3 print ' < t.txt
78
90
8
You can also use sed in-place without a temp file: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 2 '12 at 23:46
1
Thanks @YanickGirouard, @IgnacioVazquezAbrams! You two have just saved me a ton of manual labor on my research! :)
– Paul
Sep 6 '12 at 5:22
2
@Svetlanased -ispecifically. 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 7 '14 at 22:21
4
how about explaining what '1,3d', +4, et.c. means? The question was for n lines, but you didn't tell what n is (as apparently n is 2 in your examples, though it's not obvious for a noob what to change in order to change n)
– Robin Manoli
Feb 1 '15 at 10:29
2
This uses a temp file so not very useful for a 100% util disk space. Would be interesting to have a solution that does this literally "in-place".
– Shai
Sep 2 '16 at 21:09
|
show 5 more comments
As long as the file is not a symlink or hardlink, you can use sed, tail, or awk. Example below.
$ cat t.txt
12
34
56
78
90
sed
$ sed -e '1,3d' < t.txt
78
90
You can also use sed in-place without a temp file: 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.
tail
$ tail -n +4 t.txt
78
90
awk
$ awk 'NR > 3 print ' < t.txt
78
90
8
You can also use sed in-place without a temp file: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 2 '12 at 23:46
1
Thanks @YanickGirouard, @IgnacioVazquezAbrams! You two have just saved me a ton of manual labor on my research! :)
– Paul
Sep 6 '12 at 5:22
2
@Svetlanased -ispecifically. 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 7 '14 at 22:21
4
how about explaining what '1,3d', +4, et.c. means? The question was for n lines, but you didn't tell what n is (as apparently n is 2 in your examples, though it's not obvious for a noob what to change in order to change n)
– Robin Manoli
Feb 1 '15 at 10:29
2
This uses a temp file so not very useful for a 100% util disk space. Would be interesting to have a solution that does this literally "in-place".
– Shai
Sep 2 '16 at 21:09
|
show 5 more comments
As long as the file is not a symlink or hardlink, you can use sed, tail, or awk. Example below.
$ cat t.txt
12
34
56
78
90
sed
$ sed -e '1,3d' < t.txt
78
90
You can also use sed in-place without a temp file: 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.
tail
$ tail -n +4 t.txt
78
90
awk
$ awk 'NR > 3 print ' < t.txt
78
90
As long as the file is not a symlink or hardlink, you can use sed, tail, or awk. Example below.
$ cat t.txt
12
34
56
78
90
sed
$ sed -e '1,3d' < t.txt
78
90
You can also use sed in-place without a temp file: 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.
tail
$ tail -n +4 t.txt
78
90
awk
$ awk 'NR > 3 print ' < t.txt
78
90
edited Jan 7 '14 at 22:55
user13764
answered May 2 '12 at 23:40
Ignacio Vazquez-AbramsIgnacio Vazquez-Abrams
33.7k66982
33.7k66982
8
You can also use sed in-place without a temp file: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 2 '12 at 23:46
1
Thanks @YanickGirouard, @IgnacioVazquezAbrams! You two have just saved me a ton of manual labor on my research! :)
– Paul
Sep 6 '12 at 5:22
2
@Svetlanased -ispecifically. 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 7 '14 at 22:21
4
how about explaining what '1,3d', +4, et.c. means? The question was for n lines, but you didn't tell what n is (as apparently n is 2 in your examples, though it's not obvious for a noob what to change in order to change n)
– Robin Manoli
Feb 1 '15 at 10:29
2
This uses a temp file so not very useful for a 100% util disk space. Would be interesting to have a solution that does this literally "in-place".
– Shai
Sep 2 '16 at 21:09
|
show 5 more comments
8
You can also use sed in-place without a temp file: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 2 '12 at 23:46
1
Thanks @YanickGirouard, @IgnacioVazquezAbrams! You two have just saved me a ton of manual labor on my research! :)
– Paul
Sep 6 '12 at 5:22
2
@Svetlanased -ispecifically. 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 7 '14 at 22:21
4
how about explaining what '1,3d', +4, et.c. means? The question was for n lines, but you didn't tell what n is (as apparently n is 2 in your examples, though it's not obvious for a noob what to change in order to change n)
– Robin Manoli
Feb 1 '15 at 10:29
2
This uses a temp file so not very useful for a 100% util disk space. Would be interesting to have a solution that does this literally "in-place".
– Shai
Sep 2 '16 at 21:09
8
8
You can also use sed in-place without a temp file:
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 2 '12 at 23:46
You can also use sed in-place without a temp file:
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 2 '12 at 23:46
1
1
Thanks @YanickGirouard, @IgnacioVazquezAbrams! You two have just saved me a ton of manual labor on my research! :)
– Paul
Sep 6 '12 at 5:22
Thanks @YanickGirouard, @IgnacioVazquezAbrams! You two have just saved me a ton of manual labor on my research! :)
– Paul
Sep 6 '12 at 5:22
2
2
@Svetlana
sed -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 7 '14 at 22:21
@Svetlana
sed -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 7 '14 at 22:21
4
4
how about explaining what '1,3d', +4, et.c. means? The question was for n lines, but you didn't tell what n is (as apparently n is 2 in your examples, though it's not obvious for a noob what to change in order to change n)
– Robin Manoli
Feb 1 '15 at 10:29
how about explaining what '1,3d', +4, et.c. means? The question was for n lines, but you didn't tell what n is (as apparently n is 2 in your examples, though it's not obvious for a noob what to change in order to change n)
– Robin Manoli
Feb 1 '15 at 10:29
2
2
This uses a temp file so not very useful for a 100% util disk space. Would be interesting to have a solution that does this literally "in-place".
– Shai
Sep 2 '16 at 21:09
This uses a temp file so not very useful for a 100% util disk space. Would be interesting to have a solution that does this literally "in-place".
– Shai
Sep 2 '16 at 21:09
|
show 5 more comments
sed -i '1,3d' file.txt
This deletes first 3 line from file.txt.
add a comment |
sed -i '1,3d' file.txt
This deletes first 3 line from file.txt.
add a comment |
sed -i '1,3d' file.txt
This deletes first 3 line from file.txt.
sed -i '1,3d' file.txt
This deletes first 3 line from file.txt.
answered Dec 28 '17 at 13:13
alhelalalhelal
386517
386517
add a comment |
add a comment |
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
2
"tabulated" usually means "pretty-printed in a table", not "indented with tab characters".
– Ignacio Vazquez-Abrams
May 3 '12 at 2:14
@IgnacioVazquez-Abrams I know. The pretty-printed table sometimes uses tab characters, that's easier to spot than aligned columns. Of course, if Paul gave a sample input, I could give a better matcher.
– Gilles
May 3 '12 at 10:04
add a comment |
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
2
"tabulated" usually means "pretty-printed in a table", not "indented with tab characters".
– Ignacio Vazquez-Abrams
May 3 '12 at 2:14
@IgnacioVazquez-Abrams I know. The pretty-printed table sometimes uses tab characters, that's easier to spot than aligned columns. Of course, if Paul gave a sample input, I could give a better matcher.
– Gilles
May 3 '12 at 10:04
add a comment |
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
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
answered May 3 '12 at 1:06
GillesGilles
544k12811041621
544k12811041621
2
"tabulated" usually means "pretty-printed in a table", not "indented with tab characters".
– Ignacio Vazquez-Abrams
May 3 '12 at 2:14
@IgnacioVazquez-Abrams I know. The pretty-printed table sometimes uses tab characters, that's easier to spot than aligned columns. Of course, if Paul gave a sample input, I could give a better matcher.
– Gilles
May 3 '12 at 10:04
add a comment |
2
"tabulated" usually means "pretty-printed in a table", not "indented with tab characters".
– Ignacio Vazquez-Abrams
May 3 '12 at 2:14
@IgnacioVazquez-Abrams I know. The pretty-printed table sometimes uses tab characters, that's easier to spot than aligned columns. Of course, if Paul gave a sample input, I could give a better matcher.
– Gilles
May 3 '12 at 10:04
2
2
"tabulated" usually means "pretty-printed in a table", not "indented with tab characters".
– Ignacio Vazquez-Abrams
May 3 '12 at 2:14
"tabulated" usually means "pretty-printed in a table", not "indented with tab characters".
– Ignacio Vazquez-Abrams
May 3 '12 at 2:14
@IgnacioVazquez-Abrams I know. The pretty-printed table sometimes uses tab characters, that's easier to spot than aligned columns. Of course, if Paul gave a sample input, I could give a better matcher.
– Gilles
May 3 '12 at 10:04
@IgnacioVazquez-Abrams I know. The pretty-printed table sometimes uses tab characters, that's easier to spot than aligned columns. Of course, if Paul gave a sample input, I could give a better matcher.
– Gilles
May 3 '12 at 10:04
add a comment |
You can use Vim in Ex mode:
ex -sc '1d5|x' file
1move to first line5select 5 linesddeletexsave and close
add a comment |
You can use Vim in Ex mode:
ex -sc '1d5|x' file
1move to first line5select 5 linesddeletexsave and close
add a comment |
You can use Vim in Ex mode:
ex -sc '1d5|x' file
1move to first line5select 5 linesddeletexsave and close
You can use Vim in Ex mode:
ex -sc '1d5|x' file
1move to first line5select 5 linesddeletexsave and close
edited Apr 17 '16 at 14:34
answered Apr 17 '16 at 1:14
Steven PennySteven Penny
1
1
add a comment |
add a comment |
echo "anb" | sed '1d' # deletes first line
cat list.txt | sed '1d' > list.csv # read list.txt and write list.csv without first line
Other useful commands:
grep '^|' # finds first character (pipe|)
sed 's/|//g' # deletes pipe
sed 's/ //g' # deletes space
add a comment |
echo "anb" | sed '1d' # deletes first line
cat list.txt | sed '1d' > list.csv # read list.txt and write list.csv without first line
Other useful commands:
grep '^|' # finds first character (pipe|)
sed 's/|//g' # deletes pipe
sed 's/ //g' # deletes space
add a comment |
echo "anb" | sed '1d' # deletes first line
cat list.txt | sed '1d' > list.csv # read list.txt and write list.csv without first line
Other useful commands:
grep '^|' # finds first character (pipe|)
sed 's/|//g' # deletes pipe
sed 's/ //g' # deletes space
echo "anb" | sed '1d' # deletes first line
cat list.txt | sed '1d' > list.csv # read list.txt and write list.csv without first line
Other useful commands:
grep '^|' # finds first character (pipe|)
sed 's/|//g' # deletes pipe
sed 's/ //g' # deletes space
answered Mar 3 at 17:51
Samran ElahiSamran Elahi
1
1
add a comment |
add a comment |
By percentage
Using bash, to clean up a file using a percentage number instead of an absolute number of lines:
sed -i -e 1,$( printf "$((`cat php_errors.log | wc -l` * 75 /100 ))" )d php_errors.log
Watch out because that command can be destructive since it deletes content in-place, without creating a copy.
It deletes the first 75% of lines from the mentioned file.
I am a bash newbie, so I am sure this could be made prettier and faster, and I welcome suggestions to achieve this.
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
By percentage
Using bash, to clean up a file using a percentage number instead of an absolute number of lines:
sed -i -e 1,$( printf "$((`cat php_errors.log | wc -l` * 75 /100 ))" )d php_errors.log
Watch out because that command can be destructive since it deletes content in-place, without creating a copy.
It deletes the first 75% of lines from the mentioned file.
I am a bash newbie, so I am sure this could be made prettier and faster, and I welcome suggestions to achieve this.
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
By percentage
Using bash, to clean up a file using a percentage number instead of an absolute number of lines:
sed -i -e 1,$( printf "$((`cat php_errors.log | wc -l` * 75 /100 ))" )d php_errors.log
Watch out because that command can be destructive since it deletes content in-place, without creating a copy.
It deletes the first 75% of lines from the mentioned file.
I am a bash newbie, so I am sure this could be made prettier and faster, and I welcome suggestions to achieve this.
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
By percentage
Using bash, to clean up a file using a percentage number instead of an absolute number of lines:
sed -i -e 1,$( printf "$((`cat php_errors.log | wc -l` * 75 /100 ))" )d php_errors.log
Watch out because that command can be destructive since it deletes content in-place, without creating a copy.
It deletes the first 75% of lines from the mentioned file.
I am a bash newbie, so I am sure this could be made prettier and faster, and I welcome suggestions to achieve this.
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered yesterday
pgrpgr
1011
1011
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
pgr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f37790%2fhow-do-i-delete-the-first-n-lines-of-an-ascii-file-using-shell-commands%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-bash, shell-script, text-processing