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
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
If you explain your input and output,it will be better to understand by us.
What do you mean exactly by input and output ?
No Idea what you are doing but if you want to use shell variable in sed...
sed '/'"${exclusion}"'/d' infile
@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
alpha3363:
@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
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?
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:
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
Your sed commands seems to have all messed up. You dont usually assign the o/p of a sed command to a variable like the way you are doing. For example
exclusions="sed -e /${exclusion}/d"
should be something like
exclusions=`sed -e "/${exclusion}/d"`
But I aint sure what exactly you are trying to do here.
The better approach would be to loop through the files:
cp file file_bakup
while read pattern
do
sed "/$pattern/d" file > tmpfile
mv tmpfile file
done < pattfile
cheers,
Devaraj Takhellambam