0

I am not getting expected results from sed 's/$/2021-07-21/' demotoytable.csv

Before the command the top 3 lines look like:

urlhm|main_code|description|taxable|itemnum|xtras
t3mr.com/guitar/qrc/G19RTE000000753|G19RTE0000007530|Promo_labor_day_006|Consignment|7522831|bag
t3mr.com/guitar/qrc/G19RTE000000753|G19RTE0000007530|Promo_labor_day_006|Consignment|7522835|box
t3mr.com/guitar/qrc/G19RTE000000753|G19RTE0000007530|Promo_labor_day_006|Consignment|7522839|case

But after running the command sed 's/$/|2021-07-21/' demotoytable.csv I get this result:

|2021-07-21code|description|taxable|itemnum|xtras
|2021-07-21itar/qrc/G19RTE000000753|G19RTE0000007530|Promo_labor_day_006|Consignment|7522831|bag
|2021-07-21itar/qrc/G19RTE000000753|G19RTE0000007530|Promo_labor_day_006|Consignment|7522835|box
|2021-07-21itar/qrc/G19RTE000000753|G19RTE0000007530|Promo_labor_day_006|Consignment|7522839|case

Any ideas on why this is happening, or better yet how to fix? I want each line to end w "|2021-07-21", not begin with it. On a Mac Pro running Big Sur

Thanks

Thom Rogers
  • 1,385
  • 2
  • 20
  • 33
  • 2
    SUGGESTION: Try "&": https://unix.stackexchange.com/questions/296705/using-sed-with-ampersand. SEE ALSO: https://stackoverflow.com/a/61154091/421195 – paulsm4 Jul 22 '21 at 20:59
  • 5
    It is because your input file is ending with carriage return or `\r`. Remove that using `tr` or `sed` first. – anubhava Jul 22 '21 at 21:12

1 Answers1

0

Remove carriage returns and then add the texts you wish to add:

sed 's/\r$//; s/$/|2021-07-21/' demotoytable.csv

s/\r$// removes carriage returns at the end of lines, s/$/|2021-07-21/ in its turn appends the value of your choice at the end of lines.

Ryszard Czech
  • 18,032
  • 4
  • 24
  • 37