Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-10-2010
Registered User
 

Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Using SED command in a shell script: Unterminated address regex

Hi All,

I am trying to use a sed command in a shell script in order to delete some lines in a file and I got the following error message.
I don't understand why it is not working 'cause I have tried with simple quotes, then with double-quotes, and it is not working.

sed: -e expression #1, char 4: Unterminated address regex

Here below is the code I used in my shell script:

1- First I read a Exclusion file where I retrieve in each line a Pattern
2- Then I use this pattern in sed cmd to delete the corresponding line and put the result in another file

Code:
buildGrep()
{
  nbl=`cat $exclusionFile | wc -l`
  i=1
  exclusion=`cat $exclusionFile | tail -${i} | head -1`
  exclusions="sed -e /${exclusion}/d"
  while [ $i -lt $((nbl+1)) ];
  do
         exclusions="${exclusions} -e '/${exclusion}/d'"
         i=`expr $i + 1`
         exclusion=`cat $exclusionFile | tail -${i} | head -1`
  done
  FinalExclusion=`${exclusions} <${TemporaryFile} >${aFiltered_monerrFile}`
}
aDate=`date '+%y.%m.%d_%H.%M.%S'`
aFiltered_monerrFile=Filtered_File.txt
TemporaryFile=TempFile$aDate.txt
ssh xxxx@xxxxx fgrep "2010\/03\/10" xxxxxxxxxxxxx/OriginalFile > $TemporaryFile
exclusionFile=xxxxx.dat
buildGrep

Have somebody any idea ?

Thank you in advance,
Alpha

Last edited by Franklin52; 03-10-2010 at 05:47 AM.. Reason: Please use code tags!
Sponsored Links
    #2  
Old 03-10-2010
vivekraj's Avatar
Registered User
 

Join Date: Feb 2010
Location: Chennai
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
If you explain your input and output,it will be better to understand by us.
Sponsored Links
    #3  
Old 03-10-2010
Registered User
 

Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
What do you mean exactly by input and output ?
    #4  
Old 03-10-2010
Registered User
 

Join Date: Sep 2008
Location: In the beautiful World...
Posts: 509
Thanks: 9
Thanked 27 Times in 27 Posts
No Idea what you are doing but if you want to use shell variable in sed...

Code:
sed  '/'"${exclusion}"'/d' infile

Sponsored Links
    #5  
Old 03-10-2010
Registered User
 

Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
@malcomex999:
I have tried with the simple-quote/double-quotes, but I still have the same issue:

sed: -e expression #1, char 3: Unterminated address regex
Sponsored Links
    #6  
Old 03-10-2010
Registered User
 

Join Date: Sep 2008
Location: In the beautiful World...
Posts: 509
Thanks: 9
Thanked 27 Times in 27 Posts
Quote:
Originally Posted by Alpha3363 View Post
@malcomex999:
I have tried with the simple-quote/double-quotes, but I still have the same issue:

sed: -e expression #1, char 3: Unterminated address regex

Code:
buildGrep()
{
  nbl=`cat $exclusionFile | wc -l`
  i=1
  exclusion=`cat $exclusionFile | tail -${i} | head -1`
  exclusions="sed -e /${exclusion}/d"
  while [ $i -lt $((nbl+1)) ];
  do
         exclusions="${exclusions} -e '/${exclusion}/d'"
         i=`expr $i + 1`
         exclusion=`cat $exclusionFile | tail -${i} | head -1`
  done
  FinalExclusion=`${exclusions} <${TemporaryFile} >${aFiltered_monerrFile}`
}
aDate=`date '+%y.%m.%d_%H.%M.%S'`
aFiltered_monerrFile=Filtered_File.txt
TemporaryFile=TempFile$aDate.txt
ssh xxxx@xxxxx fgrep "2010\/03\/10" xxxxxxxxxxxxx/OriginalFile > $TemporaryFile
exclusionFile=xxxxx.dat
buildGrep

But i see above, there is no filename to read from for the sed command...(in red)

Can you explain what you are trying to achieve?
Sponsored Links
    #7  
Old 03-10-2010
Registered User
 

Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, because in this line, I just reteieve on Line from my exclusion file.
After that I concatene all the exclusion patterns with my sed command in green.
The real call off the sed command is in the blue line with input and output file:


Code:
buildGrep()
{
  nbl=`cat $exclusionFile | wc -l`
  i=1
  exclusion=`cat $exclusionFile | tail -${i} | head -1`
  exclusions="sed -e /${exclusion}/d"
  while [ $i -lt $((nbl+1)) ];
  do
         exclusions="${exclusions} -e '/${exclusion}/d'"
         i=`expr $i + 1`
         exclusion=`cat $exclusionFile | tail -${i} | head -1`
  done
  FinalExclusion=`${exclusions} <${TemporaryFile} >${aFiltered_monerrFile}`
}
aDate=`date '+%y.%m.%d_%H.%M.%S'`
aFiltered_monerrFile=Filtered_File.txt
TemporaryFile=TempFile$aDate.txt
ssh xxxx@xxxxx fgrep "2010\/03\/10" xxxxxxxxxxxxx/OriginalFile > $TemporaryFile
exclusionFile=xxxxx.dat
buildGrep
buildGrep()
{
  nbl=`cat $exclusionFile | wc -l`
  i=1
  exclusion=`cat $exclusionFile | tail -${i} | head -1`
  exclusions="sed -e /'"${exclusion}"'/d"
  while [ $i -lt $((nbl+1)) ];
  do
         exclusions="${exclusions} -e '/${exclusion}/d'"
         i=`expr $i + 1`
         exclusion=`cat $exclusionFile | tail -${i} | head -1`
  done
  FinalExclusion=`${exclusions} <${TemporaryFile} >${aFiltered_monerrFile}`
}
aDate=`date '+%y.%m.%d_%H.%M.%S'`
aFiltered_monerrFile=Filtered_File.txt
TemporaryFile=TempFile$aDate.txt
ssh xxxx@xxxxx fgrep "2010\/03\/10" xxxxxxxxxxxxx/OriginalFile > $TemporaryFile
exclusionFile=xxxxx.dat
buildGrep

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regex to match IP address glev2005 UNIX for Advanced & Expert Users 5 03-06-2010 07:03 AM
Shell script regex help: accept only 3 file extensions grep01 Shell Programming and Scripting 9 11-13-2009 12:30 AM
Checking the password thru Regex via Shell Script gudikal_karanam Shell Programming and Scripting 1 09-18-2009 11:57 AM
regex/shell script to Parse through XML Records Jerrad Shell Programming and Scripting 5 06-12-2009 05:59 PM
EMail Address Validation (Shell Script) balajiora Shell Programming and Scripting 3 05-20-2009 03:41 PM



All times are GMT -4. The time now is 12:55 AM.