0

I have a directory in which files are created as abc.sh.ID.datetimestamp.id.log
In the filename abc.sh, the ID is always the same (there are 1000's of .sh's and ID's combination in the environment). datetimestamp and id change for each file generated. I am trying to use ls -ltr abc.sh.*.log. But it returns all filenames which match the expression. I need only unique ID filenames not caring what datetimestamp and id are.

Can anyone please help?

  • anyone who can help with this? – kumar2008 Aug 20 '15 at 4:15
5

I should think:

ls ./* | cut -d '.' -f 1,2,3 | sort -u

will get you there, this essentially lists the contents of the directory, then cuts off everything after the third '.' and then sorts the lines and removes duplicates. The end result would be a list of 'abc.sh.ID'.

If you want you loop through this new list and do an 'ls [line]*' to get the datetimestamp.id.log as well, which would result in the contents of the directory grouped by ID.

  • Dave thanks for your reply. When I run that it errors out giving ksh: /usr/bin/ls: 0403-027 The parameter list is too long. I tried from bash as well it says: bash: /usr/bin/ls: The parameter or environment lists are too long. Other thing is I need "abc.sh" in the search for sure – kumar2008 Aug 19 '15 at 20:42
  • @kumar2008 you can try using just ls the ./* is redundant, but should be accepted (for whatever reason it sounds like all of the files in the directory are being passed as an argument). Alternatively you can replace ls ./* with find ./, you'll need to provide the -maxdepth option if there are directories in there as well though. The command I provided will still include the 'abc.sh.ID' as I mentioned. – Centimane Aug 20 '15 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.