I am new to UNIX Shell. I want to list the files names in the current directory that are not start with 'AB' and have at least two characters. For example, say I have those files in the current directory: AB, AC, AD, AE, B, C. After executing the command, AC, AD, AE will be listed on the screen.
My strategy is to get those files that their names have more than one character and use pipeline to redirect to another echo for filtering those files names that do not start with AB. I have tried the following command:
It seems it works fine, however, I am not sure wether I am correct. Is there any other way to do this? BTW, I am getting confused about the the differences between
and
I know that the first one is pass the results that do not start with AB to the second echo to filter files names longer than one character, the second one does the reverse order, however, they gave me different answers. I thought they should perform exactly the same. Could anybody explain the differences? and why I get different answers? I appreciate that.
Last edited by Scrutinizer; 05-13-2013 at 05:35 PM..
Reason: code tags
echo cannot accept stdin, so you cannot pipe output of another command into it. But how about just:
I want to retrieve files whose names have at least two characters but do not start with 'AB'. The command : ls [!A][!B]* just list files that do not start with 'AB', thus, file AC will not appear in the result, however, it should be.
It seems it works perfectly fine. Can I understand the code in this way that [!A]?* filters those files not start with A, however, have at least two characters and A[!B]* catches those files start with A, however, not AB? Does ls command combine the results in terms of two criteria together? Thanks!
Your understanding is correct for the first part, but
Are two patterns that produce one field list, so it is not the command that glues them together. These fields are input to the command ls. They would need to be mutually exclusive.
You can see what is looks like if you first type:
and issue the command. Later you can switch it off with set +x
If for either pattern there is at least one file present, then you could for example also use:
This User Gave Thanks to Scrutinizer For This Post:
Hello All,
just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table.
Can you please suggest why? or any better idea?
export FILE="/abc/autom/file/geo_JOB.csv"
Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Hello,
I have files in a directory with names like,
./f0/84.40_E1200_85.39_E1300_f0_r00_1300-ON-0.25_S7A_v4_47.19.1.out.txt
./f0/84.40_E1200_85.83_E1200_f0_r00_1200-ON-0.25_S7A_v4_47.19.1.out.txt
./f0/84.60_E1100_86.45_E1100_f0_r00_1100-ON-0.25_S7A_v4_47.19.1.out.txt... (5 Replies)
Hey everyone! I made a shell script that would go through a file and replace any phrase or letter with another phrase or letter. Helps update variable names or values. The following code is this:
#!/bin/sh
Word1="$1"
Replace1="$2"
File1="$3"
arg=$( echo "$Word1" | sed 's:\:\\&:g' )... (3 Replies)
Hi,
I am using ksh , i have requirement to run 4 functions in background , 4 functions call are available in a case that case is also in function, i need to execute 1st function it should run in background and return to case and next i will call 2nd function it should run in background and... (8 Replies)
I want to list files that end with .c in the direct subdirectory of the current directory. I have tried the following command:
find ./ -mindepth 2 -maxdepth 2 -name "*.c"
Is that right? Or is there any easier way to handle that problem?
Another problem is that I want to grep in a file to find... (5 Replies)
Hi,
I look for a awk one liner for below issue.
input file
ABC 1234 abc 12345
ABC 4567 678 XYZ
xyz ght 678
ABC 787 yyuu
ABC 789 7890 777
zxr hyip hyu
mno uii 678 776
ABC ty7 888
All lines should be started with ABC as first field. If a record has another value for 1st... (7 Replies)
Hi All,
I have a problem mentioned below.
I have a script which performs line by line operations on several files.
I have a temp_file storing the list of names of the file to be validated. Right not in while loop i validate these files one by one.
Is there anyway that i can modify... (1 Reply)
Hello,
I"m a newbie :). I hope I can learn from the scripting expert.
I'm trying to use egrep and grep commands to get the total count by meeting both criteria. So far, I haven't been able to do it.
if robot = TLD and barcode = AA, then final count should be 2
if robot = TLD and... (9 Replies)
Hi all,
I am newbie in unix. Just have some doubts on how to join multiple lines into single line.
I have 1 file with following contents.
R96087641
HostName-kul480My
This is no use any more
%%
E78343970
LocalPath-/app/usr/SG
(Blank in this line)
%%
E73615740... (4 Replies)
I would like a simple shell script that will allow me to display to screen all unsuccessful su attempts in my sulog file, for the present date.
I have been trying several different combinations of commands, but I can't quite get the syntax correct.
The mess I have right now (don't laugh) is... (4 Replies)