SHELL: UNIX : Ls regular expression not working when used with variables
If i do below command in unix prompt which static values (ie 27..97), it is working fine and gives desired output
But if i want to include variables or pass arguments to regular expression then its giving me error "ls: cannot access /home/work/batch/somefilename_{27..96}.*: No such file or directory". But thats not true bec file is present but somehow with variables regex is not working.
Can someone please advise here why the regular expression is not working when using ls and {..} with variables?
Note: I am trying to store all the directory names in an array whose directory name is between two integer number
for eg there are 1-100 dir available with name file_1.some file_2.some file_3.some .. file_100.some.
If user wants to get directory from 47 till 97, then i want to read that value, store them and pass it in above ls command.
If you have any other alternative that will also help.
Hello Everyone,
I have a file sam1 with the below content
SYSYSID;MANDT;/SIE/AD_Z0M_INDX;/SIE/AD_Z0M_KEY1
echo $Regex
\bSYSYSID\b|\bMANDT\b|\b/SIE/AD_Z0M_INDX\b|\b/SIE/AD_Z0M_KEY1\b
cat sam1 | grep -Eo $Regex
I expect the result as
SYSYSID
MANDT
/SIE/AD_Z0M_INDX
/SIE/AD_Z0M_KEY1... (4 Replies)
How can I define a regular expression of a string which can start with Capital alphabet or integer (A-Z) or (0-9) and can be of any number of characters
I have tried * but its not working
could anyone please suggest? (2 Replies)
Hello ,
Could anyone help me to define the string in regular expression way .
Below is my string
\rtf1\ansi\deff0{\fonttbl{\f0\fswiss Helv;}{\f1\fnil MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs16
The string will always start as \rtf1 and... (6 Replies)
Hi all,
How am I read a file, find the match regular expression and overwrite to the same files.
open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat";
open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat";
while (<DESTINATION_FILE>)
{
# print... (1 Reply)
Hi All,
I am facing some problems with regular expression with sed.
I have a .txt file with the contents as below:
This is a dummy file
# File created to test execution of regular expression.
Hope it works out.
As in the above contents there is a blank line which does not... (4 Replies)
hi,
I have written a script to search MAC address in a given directory.
MAC address would be in format XX.XX.XX.XX.
The digits contain hexadecimal numbers.
For this i have used grep as follows.
grep -rn '^\{1,2\}\.\{1,2\}\.\{1,2\}\.\{1,2\}\$' *
This is not working as required.... (17 Replies)
I have the following code:
ls -al /bin | tr -s ' ' | grep 'x'
ls -al: Lists all the files in a given director such as /bin
tr -s ' ': removes additional spaces between characters so that there is only one space
grep 'x': match all "x" characters that are followed by a whitespace.
I was... (3 Replies)
Hi,
I have to match a certain pattern of string in my shell script:
6.0.4.11.9
7.5.1.7.1
First Number can be 6 or 7
Second number can be 0 or 5
Rest all numbers can be between 1-99
I am using following egrep:
egrep ^\.\.\.\.\$ filename
But why is the above regular... (1 Reply)
Hi,
Actually i have written one test.sh (shell program) in bash.
Here i have a variables $a which stored the value package1.
Now I want to write a regular expression inside the if command that "if $a variable contains letter p in the begining of the value package1 then it is coming true.... (5 Replies)