scripting - How can I extract a substring from the results of a cut command in unix? -


I have a file that says '|' Delimited One of the fields in the field is a time stamp. The field is in the following format: MM-dd-yyyy HH: mm: ss I want to be able to print a file on unique dates. I can use the cut command ( cut -f1 -d '|' _file_name_ | sort | uniq ') to extract a unique date. However, with part of the time zone, I see hundreds of results. After running the cut command, I want to take the substrings of eleven characters first to display specific dates. I tried to use an awk command, such as: awk '{print substr ($ 1,1-11)}' | Cut -f1 -d '|' _file_name_ | Sort | Uniq & gt; _output_file _

I have no luck. Am I going wrong about this? Is there another easy way to remove the required data? Any help would be appreciated.

It is based on the idea that the date time is in stamp field 1.

EDIT: 10 from the changed field, it is also used -U option to sort with uniq instead of sep process

You do not need to cut , Weird will do this for you.

  awk -F "|" '{Print substr ($ 10,1,11)}' _file_name_ | Sort -u & gt; _output_file_   

I hope this will be helpful.

P.S. As you appear as a new user, if you get an answer that helps you to remember to mark it as acceptable, or as a useful answer to + (or -)

Comments