remove last 10 rows of a csv file in bash












-2















i have a CSV file and want to remove the last 10 records or rows of it so if we have 100 records (100 rows) so i can delete last 10 and have just 90 rows
and i want to do it in bash(or node js if you know how to do it)










share|improve this question























  • What did you try? You can easily get it done with head.

    – Amessihel
    Nov 24 '18 at 11:06













  • how can i do this with head? i did this head -n 5 sample.csv but it removes 5 line from the csv not 5 rows

    – Vfx Master
    Nov 24 '18 at 11:09






  • 2





    Wait, what's the difference between a row and a line?

    – Amessihel
    Nov 24 '18 at 11:11






  • 1





    Are you confusing rows and columns?

    – Cyrus
    Nov 24 '18 at 11:13











  • i dont want to remove 10 line i want to remove 10 row

    – Vfx Master
    Nov 24 '18 at 11:48
















-2















i have a CSV file and want to remove the last 10 records or rows of it so if we have 100 records (100 rows) so i can delete last 10 and have just 90 rows
and i want to do it in bash(or node js if you know how to do it)










share|improve this question























  • What did you try? You can easily get it done with head.

    – Amessihel
    Nov 24 '18 at 11:06













  • how can i do this with head? i did this head -n 5 sample.csv but it removes 5 line from the csv not 5 rows

    – Vfx Master
    Nov 24 '18 at 11:09






  • 2





    Wait, what's the difference between a row and a line?

    – Amessihel
    Nov 24 '18 at 11:11






  • 1





    Are you confusing rows and columns?

    – Cyrus
    Nov 24 '18 at 11:13











  • i dont want to remove 10 line i want to remove 10 row

    – Vfx Master
    Nov 24 '18 at 11:48














-2












-2








-2








i have a CSV file and want to remove the last 10 records or rows of it so if we have 100 records (100 rows) so i can delete last 10 and have just 90 rows
and i want to do it in bash(or node js if you know how to do it)










share|improve this question














i have a CSV file and want to remove the last 10 records or rows of it so if we have 100 records (100 rows) so i can delete last 10 and have just 90 rows
and i want to do it in bash(or node js if you know how to do it)







node.js bash csv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 10:52









Vfx MasterVfx Master

74




74













  • What did you try? You can easily get it done with head.

    – Amessihel
    Nov 24 '18 at 11:06













  • how can i do this with head? i did this head -n 5 sample.csv but it removes 5 line from the csv not 5 rows

    – Vfx Master
    Nov 24 '18 at 11:09






  • 2





    Wait, what's the difference between a row and a line?

    – Amessihel
    Nov 24 '18 at 11:11






  • 1





    Are you confusing rows and columns?

    – Cyrus
    Nov 24 '18 at 11:13











  • i dont want to remove 10 line i want to remove 10 row

    – Vfx Master
    Nov 24 '18 at 11:48



















  • What did you try? You can easily get it done with head.

    – Amessihel
    Nov 24 '18 at 11:06













  • how can i do this with head? i did this head -n 5 sample.csv but it removes 5 line from the csv not 5 rows

    – Vfx Master
    Nov 24 '18 at 11:09






  • 2





    Wait, what's the difference between a row and a line?

    – Amessihel
    Nov 24 '18 at 11:11






  • 1





    Are you confusing rows and columns?

    – Cyrus
    Nov 24 '18 at 11:13











  • i dont want to remove 10 line i want to remove 10 row

    – Vfx Master
    Nov 24 '18 at 11:48

















What did you try? You can easily get it done with head.

– Amessihel
Nov 24 '18 at 11:06







What did you try? You can easily get it done with head.

– Amessihel
Nov 24 '18 at 11:06















how can i do this with head? i did this head -n 5 sample.csv but it removes 5 line from the csv not 5 rows

– Vfx Master
Nov 24 '18 at 11:09





how can i do this with head? i did this head -n 5 sample.csv but it removes 5 line from the csv not 5 rows

– Vfx Master
Nov 24 '18 at 11:09




2




2





Wait, what's the difference between a row and a line?

– Amessihel
Nov 24 '18 at 11:11





Wait, what's the difference between a row and a line?

– Amessihel
Nov 24 '18 at 11:11




1




1





Are you confusing rows and columns?

– Cyrus
Nov 24 '18 at 11:13





Are you confusing rows and columns?

– Cyrus
Nov 24 '18 at 11:13













i dont want to remove 10 line i want to remove 10 row

– Vfx Master
Nov 24 '18 at 11:48





i dont want to remove 10 line i want to remove 10 row

– Vfx Master
Nov 24 '18 at 11:48












1 Answer
1






active

oldest

votes


















2














Use the head command with a negative value of n to remove the n last lines (you're talking about rows, I assumed it was lines):



head -n -10 file.csv





share|improve this answer


























  • Thanks man it worked but with head -n -10 file.csv it removes 2 row,with -n -100 it removes 8 rows and with -n -300 removes 23 rows and i have no idea how this works but thx anyway as it solves my problem

    – Vfx Master
    Nov 24 '18 at 11:28











  • this code removes 10 line from the last how can i remove 10 rows from the last?

    – Vfx Master
    Nov 24 '18 at 11:52











  • @VfxMaster, I still don't understand what you mean by row, and what's the difference with a line. Also your results (2 rows for 10 lines, and so on) are pretty surprising. Maybe you could past it on a pastebin site and add a link here (be careful with sensitive datas).

    – Amessihel
    Nov 24 '18 at 13:12













  • @VfxMaster, also check out your ends of line. Are they a mix of Windows and Unix? Execute dos2unix your_file.csv to fix it just in case.

    – Amessihel
    Nov 24 '18 at 14:19













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53457392%2fremove-last-10-rows-of-a-csv-file-in-bash%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Use the head command with a negative value of n to remove the n last lines (you're talking about rows, I assumed it was lines):



head -n -10 file.csv





share|improve this answer


























  • Thanks man it worked but with head -n -10 file.csv it removes 2 row,with -n -100 it removes 8 rows and with -n -300 removes 23 rows and i have no idea how this works but thx anyway as it solves my problem

    – Vfx Master
    Nov 24 '18 at 11:28











  • this code removes 10 line from the last how can i remove 10 rows from the last?

    – Vfx Master
    Nov 24 '18 at 11:52











  • @VfxMaster, I still don't understand what you mean by row, and what's the difference with a line. Also your results (2 rows for 10 lines, and so on) are pretty surprising. Maybe you could past it on a pastebin site and add a link here (be careful with sensitive datas).

    – Amessihel
    Nov 24 '18 at 13:12













  • @VfxMaster, also check out your ends of line. Are they a mix of Windows and Unix? Execute dos2unix your_file.csv to fix it just in case.

    – Amessihel
    Nov 24 '18 at 14:19


















2














Use the head command with a negative value of n to remove the n last lines (you're talking about rows, I assumed it was lines):



head -n -10 file.csv





share|improve this answer


























  • Thanks man it worked but with head -n -10 file.csv it removes 2 row,with -n -100 it removes 8 rows and with -n -300 removes 23 rows and i have no idea how this works but thx anyway as it solves my problem

    – Vfx Master
    Nov 24 '18 at 11:28











  • this code removes 10 line from the last how can i remove 10 rows from the last?

    – Vfx Master
    Nov 24 '18 at 11:52











  • @VfxMaster, I still don't understand what you mean by row, and what's the difference with a line. Also your results (2 rows for 10 lines, and so on) are pretty surprising. Maybe you could past it on a pastebin site and add a link here (be careful with sensitive datas).

    – Amessihel
    Nov 24 '18 at 13:12













  • @VfxMaster, also check out your ends of line. Are they a mix of Windows and Unix? Execute dos2unix your_file.csv to fix it just in case.

    – Amessihel
    Nov 24 '18 at 14:19
















2












2








2







Use the head command with a negative value of n to remove the n last lines (you're talking about rows, I assumed it was lines):



head -n -10 file.csv





share|improve this answer















Use the head command with a negative value of n to remove the n last lines (you're talking about rows, I assumed it was lines):



head -n -10 file.csv






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 11:24

























answered Nov 24 '18 at 11:10









AmessihelAmessihel

1,9691723




1,9691723













  • Thanks man it worked but with head -n -10 file.csv it removes 2 row,with -n -100 it removes 8 rows and with -n -300 removes 23 rows and i have no idea how this works but thx anyway as it solves my problem

    – Vfx Master
    Nov 24 '18 at 11:28











  • this code removes 10 line from the last how can i remove 10 rows from the last?

    – Vfx Master
    Nov 24 '18 at 11:52











  • @VfxMaster, I still don't understand what you mean by row, and what's the difference with a line. Also your results (2 rows for 10 lines, and so on) are pretty surprising. Maybe you could past it on a pastebin site and add a link here (be careful with sensitive datas).

    – Amessihel
    Nov 24 '18 at 13:12













  • @VfxMaster, also check out your ends of line. Are they a mix of Windows and Unix? Execute dos2unix your_file.csv to fix it just in case.

    – Amessihel
    Nov 24 '18 at 14:19





















  • Thanks man it worked but with head -n -10 file.csv it removes 2 row,with -n -100 it removes 8 rows and with -n -300 removes 23 rows and i have no idea how this works but thx anyway as it solves my problem

    – Vfx Master
    Nov 24 '18 at 11:28











  • this code removes 10 line from the last how can i remove 10 rows from the last?

    – Vfx Master
    Nov 24 '18 at 11:52











  • @VfxMaster, I still don't understand what you mean by row, and what's the difference with a line. Also your results (2 rows for 10 lines, and so on) are pretty surprising. Maybe you could past it on a pastebin site and add a link here (be careful with sensitive datas).

    – Amessihel
    Nov 24 '18 at 13:12













  • @VfxMaster, also check out your ends of line. Are they a mix of Windows and Unix? Execute dos2unix your_file.csv to fix it just in case.

    – Amessihel
    Nov 24 '18 at 14:19



















Thanks man it worked but with head -n -10 file.csv it removes 2 row,with -n -100 it removes 8 rows and with -n -300 removes 23 rows and i have no idea how this works but thx anyway as it solves my problem

– Vfx Master
Nov 24 '18 at 11:28





Thanks man it worked but with head -n -10 file.csv it removes 2 row,with -n -100 it removes 8 rows and with -n -300 removes 23 rows and i have no idea how this works but thx anyway as it solves my problem

– Vfx Master
Nov 24 '18 at 11:28













this code removes 10 line from the last how can i remove 10 rows from the last?

– Vfx Master
Nov 24 '18 at 11:52





this code removes 10 line from the last how can i remove 10 rows from the last?

– Vfx Master
Nov 24 '18 at 11:52













@VfxMaster, I still don't understand what you mean by row, and what's the difference with a line. Also your results (2 rows for 10 lines, and so on) are pretty surprising. Maybe you could past it on a pastebin site and add a link here (be careful with sensitive datas).

– Amessihel
Nov 24 '18 at 13:12







@VfxMaster, I still don't understand what you mean by row, and what's the difference with a line. Also your results (2 rows for 10 lines, and so on) are pretty surprising. Maybe you could past it on a pastebin site and add a link here (be careful with sensitive datas).

– Amessihel
Nov 24 '18 at 13:12















@VfxMaster, also check out your ends of line. Are they a mix of Windows and Unix? Execute dos2unix your_file.csv to fix it just in case.

– Amessihel
Nov 24 '18 at 14:19







@VfxMaster, also check out your ends of line. Are they a mix of Windows and Unix? Execute dos2unix your_file.csv to fix it just in case.

– Amessihel
Nov 24 '18 at 14:19




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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%2fstackoverflow.com%2fquestions%2f53457392%2fremove-last-10-rows-of-a-csv-file-in-bash%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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks