Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    189

    URGENT: Help with AWK or maybe SED.


    I am in need of urgent help. I have some data that I need to edit before it gets processed. I hope I can do this with either sed or awk. Here is what my data looks like

    Code:
    20130306,Wednesday,1785436,8:02,10:01,
    20130307,Thursday,1785892,10:16,11:32,
    20130308,Friday,1786359,11:04,12:51,
    20130305,Tuesday,1785122,11:39,13:15,
    20130304,Monday,1784664,10:40,14:39,
    20130306,Wednesday,1785470,9:53,11:10,
    20130307,Thursday,1785959,13:00,15:00,
    20130307,Thursday,1785960,13:00,15:00,
    20130307,Thursday,1785961,13:00,15:00,
    20130307,Thursday,1785962,13:00,15:00,
    What I need to do is add the data in the first column to the beginning of 4 and 5 so it looks like

    Code:
    20130306,Wednesday,1785436,20130306 8:02,20130306 10:01,
    20130307,Thursday,1785892,20130307 10:16,20130307 11:32,
    20130308,Friday,1786359,20130308 11:04,20130308 12:51,
    20130305,Tuesday,1785122,20130305 11:39,20130305 13:15,
    20130304,Monday,1784664,20130304 10:40,20130304 14:39,
    20130306,Wednesday,1785470,20130306 9:53,20130306 11:10,
    20130307,Thursday,1785959,20130307 13:00,20130307 15:00,
    20130307,Thursday,1785960,20130307 13:00,20130307 15:00,
    20130307,Thursday,1785961,20130307 13:00,20130307 15:00,
    20130307,Thursday,1785962,20130307 13:00,20130307 15:00,
    Can this be done? can someone please help.


    Thanks

    Mac

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,966
    One way to do this:
    Code:
    awk -F ',' '{ print $1 "," $2 "," $3 "," $1 " " $4 "," $1 " " $5 ","}' < datafile
    Other than that:
    I dont know your exact usecase.
    There is some sense in having a complete start and endtime, hence adding the date is ok.
    Although I would suggest using unix timestamps here.
    But if there is a start and endtime then the first and second columns are redundant, as they can easily be calculated from either start or endtime.
    You must always face the curtain with a bow.

  3. #3
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    189
    Thank you so much, that worked great.

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •