Everyday I have to get a list of files in a directory with a special condition and feed this list to a for loop to be processed. Since I do not use Unix all the time, it is tricky for me to get that list of files. So, the question is whether there are commands that will give me the file names with a specific condition. See explanation and example below.
This is what I have to do.
Do ls -l to show all the files
Look for the last file that has a .x at the end
Get all the file names after the last .x files
Type in for x in and then copy-paste each file name separated by a space after the word in
Here is an example:
Type in ls -l and get the following list of files
The last file with a .x suffix is A4.j.x
So, the files after the last .x file are:
The for loop command will look like the following. I have to manually copy-paste the file names in.
for x in A5.k.l.m A6.n.o.p Is there a way to get the file name list with a command and then feed/pipe it to the for command?
I apologize if this is not clear. Please let me know if more clarification is needed.
Thank you.
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by RudiC; 06-29-2018 at 01:07 PM..
Reason: Added CODE tags, removed all kinds of formatting.
The simple
correctly handles filenames with special characters.
Use quotes for correctly printing an array of strings:
Compare with
The @ lets the shell split on array elements (and parameters) despite the quotes.
Well, here is what I got when I typed in
As far as the ls version, i do not know how to search for that.
The files do not start with an A. I just happened to pick that as examples. There are numbers imbedded in the file names which are the dates & times the files were received and created.
I have a sample server name listed in variable as below:
var="server-13"
I need to check if the 7th character on $var is number 1
whichenv=`echo "$var"| head -c 7 | tail -c 1`
if ]; then
echo "9 found"
else
echo "9 Not Found"
fi
Output:
This works... (3 Replies)
Hi Friends,
Hope all is well.
I have an input file like this
a gene1 10
b gene1 2
c gene2 20
c gene3 10
d gene4 5
e gene5 6
Steps to reach output.
1. Print unique values of column1 as column of the matrix, which will be
a
b
c (5 Replies)
Hi,
I have file
#cat drivers.txt
fcs0
fcs1
vscsi1
vscsi2
In this i need to check the availabality of "fcs" or "vscsi" alone not vscsi0,fcs1
I tried with "if condition" but it is not working.
cat drivers.txt| while read ADAP
do
echo "Checking for $ADAP"
if ;then
echo "FC... (9 Replies)
Hi Friends,
I have an input file like this
chr1 100 200
chr1 200 300
chr1 300 400
chr1 400 500
chr1 500 600
chr1 600 700
chr1 700 800
chr1 800 900
chr1 900 920
chr1 940 960
I would like to get the first line's second column and the fifth line's 3rd column as one single line. This... (13 Replies)
Hi All,
I have following html code
<TR><TD>9</TD><TD>AR_TVR_TBS </TD><TD>85000</TD><TD>39938</TD><TD>54212</TD><TD>46</TD></TR>
<TR><TD>10</TD><TD>ASCV_SMY_TBS </TD><TD>69880</TD><TD>33316</TD><TD>45698</TD><TD>47</TD></TR>
<TR><TD>11</TD><TD>ARC_TBS ... (9 Replies)
I was trying to run a code to check if a fax number is empty or not.
for that, I've written the following code which is throwing an error.
#!/bin/ksh
fax= "999-999-9999"
if ; then
fax_no="000-000-0000"
else
fax_no=$fax
fi
echo $fax_no
And I get the... (7 Replies)
Hi,
I have a log file generated by a tool which has the following look :
/tmp/releases/directory/datefilename1_release_date.zip
/tmp/releases/directory/datefilename2_release_date.zip
/tmp/releases/directory/datefilename3_release_date.zip... (8 Replies)
Hi,
I hava log file which has the following output :
Created RELEASE in dist/filename_release_1_0_20090210.zip
Created RELEASE in dist/filename_release_1_1_20090210.zip
Created RELEASE in dist/filename_release_1_3_20090210.zip
Created RELEASE in... (6 Replies)
Hi All,
I'm have a file test.txt that looks like this
1939399393
03094994949
948383
I have to check whether the first character in the first line is 1 or not. I have tried the following option but it seems to fail
head -1 test.txt | grep ^1
but it seems to display the entire... (3 Replies)