I am working on one of the script developement for my project, where I need to find the distinct types of files from given directory based on pattern provided.
for e.g. directory listing is :
Run the script : ksh find_distinct_files.ksh -Pattern *.dat.????????_??????
output should be :
similarly, there can be any other pattern too for file in given directory , below are some more examples
e.g.
1) input pattern : ???_*.dat ==>
files in directory :
output : abc.dat
My point is, there can be any pattern of the file may exists in the directory.. so I need to find the all files matching input pattern and keep distinct files type. May be in another worlds, from given String, remove portion matching the pattern and keep rest..
Can anybody give me some pointers / ideas of how this can be done.
Thanks in Advance ..
Thanks
Abhijeet R
Last edited by Corona688; 01-14-2015 at 01:03 PM..
Reason: code tags please
Your specifications are vague, so I will make an assumption:
file names have 3 dot-separated fields in them - the first two fields are to be considered.
If you want a better answer, please provide better specifications.
Thanks for quick reply, my bad that I did not clarify myself . . .
My point was, there can be any pattern of the file may exists in the directory.. so I need to find the all files matching input pattern and keep distinct files type. May be in another worlds, from given String, remove portion matching the pattern and keep rest..
e.g.
1) input pattern : ???_*.dat ==>
files in directory :
123_abc.dat
234_abc.dat
output : abc.dat
So - you want to ls the files matching the pattern and then remove the portinon matching one char wildcards ?, but keep the more generic wildcard(s) * matches? And you want to keep chars given literally, but remove single chars pre-, postfixed or interspersed in the ?s?
First, you'll have to quote the parameter when calling the script to prevent the shell from expanding it. find . -name "$1" might provide you with the desired file names. Let me think a while for the removal of the name portions.
For the first question, a possible solution is not too hard. Put
into a script and run it with your (quoted!) pattern as parameter 1. For above files, it will yield
; you may want to pipe the result through a sort -u.
---------- Post updated at 14:58 ---------- Previous update was at 14:47 ----------
The second question is driving me crazy; I think it can't be resolved without making further assumptions on the structure of the filenames to be selected. It does not discriminate the two types given from each other. Run (combined with question 1 solution from above)
as a script with "???_*.dat" as parameter 1, and it will yield
The third one I don't even dare to tackle...
---------- Post updated at 15:41 ---------- Previous update was at 14:58 ----------
Simplified version anchoring solutions for 2 and 3 at the "_" char, still not resolving above issue:
Platform :Oracle Linux 6.4
Shell : bash
The below file has 7 lines , some of them are duplicates. There are only 3 distinct lines. But why is the uniq command still showing 7 ?
I just want the distinct lines to be returned.
$ cat test.txt
SELECT FC.COORD_SET_ID FROM OM_ORDER_FLOW F, -... (2 Replies)
Find all files in the current directory only excluding hidden directories and files.
For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided.
`find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Hi ,
i need to display only one of duplicated values and merged them in one record only when tag started with 3100.2.128.8
3100.2.97.1=192.168.0.12
3100.2.128.8=418/66/03e9/0044801
3100.2.128.8=418/66/03ea/0044601
3100.2.128.8=418/66/03e9/0044801
3100.2.128.8=418/66/03ea/0044601... (5 Replies)
Hi,
I have two files of the following format
file1
chr1:345-456
chr2:123-456
chr2:455-678
chr3:456-789
chr3:444-555
file2
chr1:345-456
chr2:123-456
chr3:456-789
output (2 Replies)
Hello ,
Can anyone help me with my below query
I am trying to find a text in directory of files via below command
grep -i cmps_cgs_crs_rfnc_id *
But it returns multiple times same file name i.e if the text found in a file 4 times the file name shown 4 times in the o/p
Is... (1 Reply)
Hi,
I'm searching for a pattern 'java' under a directory but it is returning all the files containing 'java', but I want to have only distinct files not all.
please help (2 Replies)
I have a directory (and many sub dirs beneath) on AIX system, containing thousands of file. I'm looking to get a list of all directory containing "*.pdf" file.
I know basic syntax of find command, but it gives me list of all pdf files, which numbers in thousands. All I need to know is, which... (4 Replies)
Hi,
I wanted to delete all the files under a directory "/apps/tmp/" which are two weeks older. But i should not delete the sub-directories and the contents of sub-directories.
I also have searched in forum and found the following command,
find . \( ! -name . -prune \) -mtime +13 -print
... (8 Replies)
Hi all
I want to find a particular file type lets say .abc under /home/oracle/, the file name is start with 'D' and followed by ddmmyyyy date format, the file name should look like this D19092008.abc To my question, how can i perform the searching from the date 19/09/2008 to 29/09/2008. The... (3 Replies)