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)













80















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.










share|improve this question




























    80















    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.










    share|improve this question


























      80












      80








      80


      23






      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 3 '12 at 1:07









      Gilles

      544k12811041621




      544k12811041621










      asked May 2 '12 at 23:36









      PaulPaul

      1,99392127




      1,99392127




















          6 Answers
          6






          active

          oldest

          votes


















          127














          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





          share|improve this answer




















          • 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





            @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





            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


















          6














          sed -i '1,3d' file.txt



          This deletes first 3 line from file.txt.






          share|improve this answer






























            5














            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





            share|improve this answer


















            • 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














            You can use Vim in Ex mode:



            ex -sc '1d5|x' file


            1. 1 move to first line


            2. 5 select 5 lines


            3. d delete


            4. x save and close






            share|improve this answer
































              0














              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






              share|improve this answer






























                0














                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.






                share|improve this answer








                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.



















                  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
                  );



                  );













                  draft saved

                  draft discarded


















                  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









                  127














                  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





                  share|improve this answer




















                  • 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





                    @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





                    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















                  127














                  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





                  share|improve this answer




















                  • 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





                    @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





                    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













                  127












                  127








                  127







                  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





                  share|improve this answer















                  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






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  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





                    @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





                    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





                    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





                    @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





                    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













                  6














                  sed -i '1,3d' file.txt



                  This deletes first 3 line from file.txt.






                  share|improve this answer



























                    6














                    sed -i '1,3d' file.txt



                    This deletes first 3 line from file.txt.






                    share|improve this answer

























                      6












                      6








                      6







                      sed -i '1,3d' file.txt



                      This deletes first 3 line from file.txt.






                      share|improve this answer













                      sed -i '1,3d' file.txt



                      This deletes first 3 line from file.txt.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Dec 28 '17 at 13:13









                      alhelalalhelal

                      386517




                      386517





















                          5














                          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





                          share|improve this answer


















                          • 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















                          5














                          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





                          share|improve this answer


















                          • 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













                          5












                          5








                          5







                          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





                          share|improve this answer













                          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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          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












                          • 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











                          2














                          You can use Vim in Ex mode:



                          ex -sc '1d5|x' file


                          1. 1 move to first line


                          2. 5 select 5 lines


                          3. d delete


                          4. x save and close






                          share|improve this answer





























                            2














                            You can use Vim in Ex mode:



                            ex -sc '1d5|x' file


                            1. 1 move to first line


                            2. 5 select 5 lines


                            3. d delete


                            4. x save and close






                            share|improve this answer



























                              2












                              2








                              2







                              You can use Vim in Ex mode:



                              ex -sc '1d5|x' file


                              1. 1 move to first line


                              2. 5 select 5 lines


                              3. d delete


                              4. x save and close






                              share|improve this answer















                              You can use Vim in Ex mode:



                              ex -sc '1d5|x' file


                              1. 1 move to first line


                              2. 5 select 5 lines


                              3. d delete


                              4. x save and close







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Apr 17 '16 at 14:34

























                              answered Apr 17 '16 at 1:14









                              Steven PennySteven Penny

                              1




                              1





















                                  0














                                  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






                                  share|improve this answer



























                                    0














                                    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






                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      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






                                      share|improve this answer













                                      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







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 3 at 17:51









                                      Samran ElahiSamran Elahi

                                      1




                                      1





















                                          0














                                          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.






                                          share|improve this answer








                                          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.
























                                            0














                                            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.






                                            share|improve this answer








                                            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.






















                                              0












                                              0








                                              0







                                              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.






                                              share|improve this answer








                                              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.







                                              share|improve this answer








                                              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.









                                              share|improve this answer



                                              share|improve this answer






                                              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.



























                                                  draft saved

                                                  draft discarded
















































                                                  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.




                                                  draft saved


                                                  draft discarded














                                                  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





















































                                                  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

                                                  Popular posts from this blog

                                                  Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

                                                  What is this called? Old film camera viewer?What makes a good film camera?What to do with an old film camera?What should one look for when buying a used film camera?What is the value and age of this pre-1967 Ricoh 35 mm camera?DSLR recommendation, question about old Canon 35mm film Camera & lensesCan anyone identify the silver rangefinder-style camera in this advertisement?What kind of a Polaroid 600-camera is this?Will an old film camera still work even when not used in a very long time?What is this camera / Can I develop the film?How to fit an action camera into antique (bellows) housing?What to check when buying used and old film bodies?

                                                  Why is this plane circling around the Lucknow airport every day?Why do aircraft on Flight Radar 24 jump around randomly sometimes?What airport has this walkway over a taxiway?How does Chicago O'Hare's tower sequence aircraft at peak capacity?Which airport is featured in this Delta commercial?After a crash, for how long is the airport closed?Can a passenger plane stand still in the air, or hover at a fixed location above a ground?What are those trucks towing around, and why?What is this airport outside of Cairo, Egypt?Which US airport has the lowest circling MDH?What is this airport video?