Finding the file name in a directory with a pattern
I need to find the latest file -filename_YYYYMMDD in the directory DIR. the below is not working as the position is shifting each time because of the spaces between(occuring mostly at file size field as it differs every time.)
please suggest if there is other way.
Last edited by Don Cragun; 08-02-2017 at 11:20 PM..
Reason: Add CODE and ICODE tags.
I need to find the latest file -filename_YYYYMMDD in the directory DIR. the below is not working as the position is shifting each time because of the spaces between(occuring mostly at file size field as it differs every time.)
please suggest if there is other way.
There are lots of problems here:
there can't be a space before the <equals-sign> in an assignment statement,
you need to use ASCII <double-quote> characters to quote shell arguments; not a pair of Unicode <opening-double-quote> characters,
a command substitution needs to be surrounded by a pair of ASCI <back-quote> characters or (depending on what shell you're using) a $( at the start and a ) at the end; not by an ASCII <back-quote> at the start and an ASCII <apostrophe> at the end, and
there is no reason to use long format ls output when you just want the filename.
In addition to what Don has listed, you may still hit problems if there are lots of files that match the filename pattern. This is because the shell will expand the pattern to match the list of all files before passing it to ls to list them in modification time order (-t), newest first. Because of this, you might overstep the limit of the command line. You haven't suggested how many files this might match. Is it a lot?
This is a system specific limit and you may never hit the maximum command line length, but if this is the case, you might be into a rather painful process to read the timestamp on each file and sort them yourself. Perhaps something like this might do the trick:-
It's messy, I know, but it might get round the command line limit, if you were to hit that.
As well as using CODE tags as in the tutorial, please can you also include details of the OS and shell you are using on each thread. The output from uname -a and ps -o cmd= -p $$ should suffice, unless your question is hardware/devices in nature.
I hope that you don't need the above code, but it might help.
I know how to search for a pattern/regular expression in many files that I have in a directory. For example, by doing this:
grep -Ril "News/U.S." .
I can find which files contain the pattern "News/U.S." in a directory.
I am unable to accomplish about how to extend this code so that it can... (1 Reply)
Hi,
I've to find the file which has the pattern
"Delete Report for History Tables"
and need to search this file pattern from directory which has sub directories as well.
I'm using ksh 88
Please suggest me which command will be used to find the file pattern .
Thanks. (1 Reply)
i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of
value abc and ccc in the place of them.
Input File:
go to &abc=ddd;
if... (16 Replies)
I have unix file like below
>newuser
newuser
<hello
hello
newone
I want to find the unique values in the file(excluding <,>),so that the out put should be
>newuser
<hello
newone
can any body tell me what is command to get this new file. (7 Replies)
Hi All,
I am trying to find 4 latest files inside one folder having following File Name pattern and store them into 4 different variables and then use for processing in my shell script. File name is fixed length.
1) Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number... (6 Replies)
So, I know how to do some of this stuff on an individual level, but I'm drawing a blank as to how to put it all together.
I have a pattern that I'm looking for in a log file. The log file I know came in yesterday, so I want to limit the search to that day's listing of files. How would I do... (5 Replies)
I am trying to find for the pattern in first 5 bytes of every line in a text file and then generate a new file with the pattern found.
Example: expected pattern is '-' to be serached in first 5 bytes of file only.
Input File
ab-cd jan-09
ddddd jan09
cc-ww jan09
dsgdq jan-09
... (2 Replies)
Hi everyone.
Could u be so kind and help me with on "simple" shell script?
1. i need to search a file line by line for a pattern.
example of a lines in that file
2947 domain = feD,id = 00 0A 02 48 17 1E 1D 39 DE 00 0E 00,Name
Values:snNo = f10
Add AttFlag = 0
2. i need to find... (0 Replies)
Hi,
I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern.
Note:These are the samples of two files,but i can have more... (2 Replies)
hi
can i know how to locate a file in a directory by using the "find" command? i want to know the exact path the files reside in in the result.
thanks :confused: (4 Replies)