How to add date in the last column in csv file in Unix? [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I have to add date values in last columns in the csv file in Unix
how to do that ?







share|improve this question













closed as unclear what you're asking by G-Man, Kusalananda, Isaac, Jeff Schaller, αғsнιη May 29 at 14:38


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Do you want to append them to the last column, or do you want to add them as new columns at the end of each line? What dates do you want to add? Do you want multiple dates on each line or just a single date per line?
    – Kusalananda
    May 29 at 5:24











  • @Kusalananda new columns at the end of each line.. because thats what a column is. Otherwise it'd be a row.
    – jdwolf
    May 29 at 5:39






  • 1




    @jdwolf No. There's a difference between changing 1,2,3 into 1,2,3-20180529 ("adding a date to the last column") and changing it into 1,2,3,20180529 ("adding a new column with a date"). I asked since the interpretation of "adding dates in the last column" is clearly ambiguous. Also "adding dates" could mean adding multiple dates to each record. It's unclear what is meant, and what dates should be added (today's date, or depending on some files' timestamp, or depending on some other data in the file, or incrementing by one day throughout the file starting at some particular date).
    – Kusalananda
    May 29 at 5:44











  • @Kusalananda Agreed on all your points pretty much. I just like how you've worded it now is much clearly on what the OP needs to specify~ ty.
    – jdwolf
    May 29 at 6:27










  • @aakansha please do edit and update your question to clarify what exactly you want your file be by providing a fragmented input/output samples.
    – Î±Ò“sнιη
    May 29 at 7:29















up vote
-1
down vote

favorite












I have to add date values in last columns in the csv file in Unix
how to do that ?







share|improve this question













closed as unclear what you're asking by G-Man, Kusalananda, Isaac, Jeff Schaller, αғsнιη May 29 at 14:38


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Do you want to append them to the last column, or do you want to add them as new columns at the end of each line? What dates do you want to add? Do you want multiple dates on each line or just a single date per line?
    – Kusalananda
    May 29 at 5:24











  • @Kusalananda new columns at the end of each line.. because thats what a column is. Otherwise it'd be a row.
    – jdwolf
    May 29 at 5:39






  • 1




    @jdwolf No. There's a difference between changing 1,2,3 into 1,2,3-20180529 ("adding a date to the last column") and changing it into 1,2,3,20180529 ("adding a new column with a date"). I asked since the interpretation of "adding dates in the last column" is clearly ambiguous. Also "adding dates" could mean adding multiple dates to each record. It's unclear what is meant, and what dates should be added (today's date, or depending on some files' timestamp, or depending on some other data in the file, or incrementing by one day throughout the file starting at some particular date).
    – Kusalananda
    May 29 at 5:44











  • @Kusalananda Agreed on all your points pretty much. I just like how you've worded it now is much clearly on what the OP needs to specify~ ty.
    – jdwolf
    May 29 at 6:27










  • @aakansha please do edit and update your question to clarify what exactly you want your file be by providing a fragmented input/output samples.
    – Î±Ò“sнιη
    May 29 at 7:29













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have to add date values in last columns in the csv file in Unix
how to do that ?







share|improve this question













I have to add date values in last columns in the csv file in Unix
how to do that ?









share|improve this question












share|improve this question




share|improve this question








edited May 29 at 5:18









αғsнιη

14.7k82361




14.7k82361









asked May 29 at 4:55









aakansha

1




1




closed as unclear what you're asking by G-Man, Kusalananda, Isaac, Jeff Schaller, αғsнιη May 29 at 14:38


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by G-Man, Kusalananda, Isaac, Jeff Schaller, αғsнιη May 29 at 14:38


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • Do you want to append them to the last column, or do you want to add them as new columns at the end of each line? What dates do you want to add? Do you want multiple dates on each line or just a single date per line?
    – Kusalananda
    May 29 at 5:24











  • @Kusalananda new columns at the end of each line.. because thats what a column is. Otherwise it'd be a row.
    – jdwolf
    May 29 at 5:39






  • 1




    @jdwolf No. There's a difference between changing 1,2,3 into 1,2,3-20180529 ("adding a date to the last column") and changing it into 1,2,3,20180529 ("adding a new column with a date"). I asked since the interpretation of "adding dates in the last column" is clearly ambiguous. Also "adding dates" could mean adding multiple dates to each record. It's unclear what is meant, and what dates should be added (today's date, or depending on some files' timestamp, or depending on some other data in the file, or incrementing by one day throughout the file starting at some particular date).
    – Kusalananda
    May 29 at 5:44











  • @Kusalananda Agreed on all your points pretty much. I just like how you've worded it now is much clearly on what the OP needs to specify~ ty.
    – jdwolf
    May 29 at 6:27










  • @aakansha please do edit and update your question to clarify what exactly you want your file be by providing a fragmented input/output samples.
    – Î±Ò“sнιη
    May 29 at 7:29

















  • Do you want to append them to the last column, or do you want to add them as new columns at the end of each line? What dates do you want to add? Do you want multiple dates on each line or just a single date per line?
    – Kusalananda
    May 29 at 5:24











  • @Kusalananda new columns at the end of each line.. because thats what a column is. Otherwise it'd be a row.
    – jdwolf
    May 29 at 5:39






  • 1




    @jdwolf No. There's a difference between changing 1,2,3 into 1,2,3-20180529 ("adding a date to the last column") and changing it into 1,2,3,20180529 ("adding a new column with a date"). I asked since the interpretation of "adding dates in the last column" is clearly ambiguous. Also "adding dates" could mean adding multiple dates to each record. It's unclear what is meant, and what dates should be added (today's date, or depending on some files' timestamp, or depending on some other data in the file, or incrementing by one day throughout the file starting at some particular date).
    – Kusalananda
    May 29 at 5:44











  • @Kusalananda Agreed on all your points pretty much. I just like how you've worded it now is much clearly on what the OP needs to specify~ ty.
    – jdwolf
    May 29 at 6:27










  • @aakansha please do edit and update your question to clarify what exactly you want your file be by providing a fragmented input/output samples.
    – Î±Ò“sнιη
    May 29 at 7:29
















Do you want to append them to the last column, or do you want to add them as new columns at the end of each line? What dates do you want to add? Do you want multiple dates on each line or just a single date per line?
– Kusalananda
May 29 at 5:24





Do you want to append them to the last column, or do you want to add them as new columns at the end of each line? What dates do you want to add? Do you want multiple dates on each line or just a single date per line?
– Kusalananda
May 29 at 5:24













@Kusalananda new columns at the end of each line.. because thats what a column is. Otherwise it'd be a row.
– jdwolf
May 29 at 5:39




@Kusalananda new columns at the end of each line.. because thats what a column is. Otherwise it'd be a row.
– jdwolf
May 29 at 5:39




1




1




@jdwolf No. There's a difference between changing 1,2,3 into 1,2,3-20180529 ("adding a date to the last column") and changing it into 1,2,3,20180529 ("adding a new column with a date"). I asked since the interpretation of "adding dates in the last column" is clearly ambiguous. Also "adding dates" could mean adding multiple dates to each record. It's unclear what is meant, and what dates should be added (today's date, or depending on some files' timestamp, or depending on some other data in the file, or incrementing by one day throughout the file starting at some particular date).
– Kusalananda
May 29 at 5:44





@jdwolf No. There's a difference between changing 1,2,3 into 1,2,3-20180529 ("adding a date to the last column") and changing it into 1,2,3,20180529 ("adding a new column with a date"). I asked since the interpretation of "adding dates in the last column" is clearly ambiguous. Also "adding dates" could mean adding multiple dates to each record. It's unclear what is meant, and what dates should be added (today's date, or depending on some files' timestamp, or depending on some other data in the file, or incrementing by one day throughout the file starting at some particular date).
– Kusalananda
May 29 at 5:44













@Kusalananda Agreed on all your points pretty much. I just like how you've worded it now is much clearly on what the OP needs to specify~ ty.
– jdwolf
May 29 at 6:27




@Kusalananda Agreed on all your points pretty much. I just like how you've worded it now is much clearly on what the OP needs to specify~ ty.
– jdwolf
May 29 at 6:27












@aakansha please do edit and update your question to clarify what exactly you want your file be by providing a fragmented input/output samples.
– Î±Ò“sнιη
May 29 at 7:29





@aakansha please do edit and update your question to clarify what exactly you want your file be by providing a fragmented input/output samples.
– Î±Ò“sнιη
May 29 at 7:29











1 Answer
1






active

oldest

votes

















up vote
1
down vote













Simply use sed:



sed "s/$/,$(date)/" infile.csv


With formatting:



sed "s/$/,$(date +'%F %T')/" infile


  • the $ in s/$/.../ is pointing anchor to the end of line.

  • we used double-quotes to expand the command-substitution $(...) output.

  • this adds date as a new column. remove comma , before ,$(...) to append to the last column.


  • use -i option of sed to in-place change in file itself or take a backup in addition:



    sed -i.bak "s/$/,$(date +'%F %T')/" infile


see for more formatting options in man date under "FORMAT controls" section.






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Simply use sed:



    sed "s/$/,$(date)/" infile.csv


    With formatting:



    sed "s/$/,$(date +'%F %T')/" infile


    • the $ in s/$/.../ is pointing anchor to the end of line.

    • we used double-quotes to expand the command-substitution $(...) output.

    • this adds date as a new column. remove comma , before ,$(...) to append to the last column.


    • use -i option of sed to in-place change in file itself or take a backup in addition:



      sed -i.bak "s/$/,$(date +'%F %T')/" infile


    see for more formatting options in man date under "FORMAT controls" section.






    share|improve this answer



























      up vote
      1
      down vote













      Simply use sed:



      sed "s/$/,$(date)/" infile.csv


      With formatting:



      sed "s/$/,$(date +'%F %T')/" infile


      • the $ in s/$/.../ is pointing anchor to the end of line.

      • we used double-quotes to expand the command-substitution $(...) output.

      • this adds date as a new column. remove comma , before ,$(...) to append to the last column.


      • use -i option of sed to in-place change in file itself or take a backup in addition:



        sed -i.bak "s/$/,$(date +'%F %T')/" infile


      see for more formatting options in man date under "FORMAT controls" section.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        Simply use sed:



        sed "s/$/,$(date)/" infile.csv


        With formatting:



        sed "s/$/,$(date +'%F %T')/" infile


        • the $ in s/$/.../ is pointing anchor to the end of line.

        • we used double-quotes to expand the command-substitution $(...) output.

        • this adds date as a new column. remove comma , before ,$(...) to append to the last column.


        • use -i option of sed to in-place change in file itself or take a backup in addition:



          sed -i.bak "s/$/,$(date +'%F %T')/" infile


        see for more formatting options in man date under "FORMAT controls" section.






        share|improve this answer















        Simply use sed:



        sed "s/$/,$(date)/" infile.csv


        With formatting:



        sed "s/$/,$(date +'%F %T')/" infile


        • the $ in s/$/.../ is pointing anchor to the end of line.

        • we used double-quotes to expand the command-substitution $(...) output.

        • this adds date as a new column. remove comma , before ,$(...) to append to the last column.


        • use -i option of sed to in-place change in file itself or take a backup in addition:



          sed -i.bak "s/$/,$(date +'%F %T')/" infile


        see for more formatting options in man date under "FORMAT controls" section.







        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited May 29 at 5:51


























        answered May 29 at 5:03









        αғsнιη

        14.7k82361




        14.7k82361












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?