Combine text from two files, output to another

前端 未结 2 1112
太阳男子
太阳男子 2021-01-25 00:25

i\'m having a bit of a problem and i\'ve been searching allll day. this is my first Unix class don\'t be to harsh.

so this may sound fairly simple, but i can\'t get it

2条回答
  •  后悔当初
    2021-01-25 01:15

    First, sort the files using sort and then use this command:

    paste file1 file2 | awk '{print $1,$4,$2,$5}'
    

    This will bring you pretty close. After that you have to figure out how to format the time from the 24 hour format to the 12 hour format.

    If you want to avoid using sort separately, you can bring in a little more complexity like this:

    paste <(sort file1) <(sort file2) | awk '{print $1,$4,$2,$5}'
    

    Finally, if you have not yet figured out how to print the time in 12 hour format, here is your full command:

    paste <(sort file1) <(sort file2) | awk '{"date --date=\"" $5 ":00:00\" +%I%P" |& getline $5; print $1 " " $4 " " $2 " " $5 }'
    

    You can use tabs (\t) in place of spaces as connectors to get a nicely formatted output.

提交回复
热议问题