LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed: Function cannot be parsed. (https://www.linuxquestions.org/questions/programming-9/sed-function-cannot-be-parsed-792783/)

leena_d 03-03-2010 12:11 AM

sed: Function cannot be parsed.
 
I have a shell script 'Test.sh'

echo "Enter The File Name"
read FILE_NAME

echo "Enter The First Column"
read Col

RowNum=2
Diff=4
Data=" "
ColNumFrom=`grep -i $Col Data.csv | cut -d "," -f2`
ColNumFrom=`expr $ColNumFrom - 1`

sed -i "${RowNum}s@\(.\{$ColNumFrom\}\).\{$Diff\}@\1${Data}@" $FILE_NAME >> NewFile



Data.csv is

AA01,
AA02,73
AB01,303
AB02,83



When I run the File for Col 'AA02', it works fine but for Col as 'AB01', is throws following error

sed: Function 2s@\(.\{302\}\).\{4\}@\1 @ cannot be parsed.

Please Help me solve the error...

leena_d 03-03-2010 01:03 AM

what is the maximum line length sed can handle?

GrapefruiTgirl 03-03-2010 01:14 AM

According to http://sed.sourceforge.net/sedfaq6.html

Code:

6.6.1. Maximum line length

      GNU sed:        no limit
      ssed:          no limit
      sedmod v1.0:    4096 bytes
      HHsed v1.5:    4000 bytes
      sed v1.6:      [pending]

P.S. >> I'm curious why you are using the -i operator, which specifies an in-place edit, but at the same time you are directing output to another file?

Tinkster 03-03-2010 01:15 AM

For AAO2 nothing happens (well, not true, and empty NewFile gets created).

Plus you have the file-name hard-coded in the line with the grep ;}

Kenhelm 03-03-2010 03:16 AM

Some versions of sed do not work with n greater than 255 in \{n\}
This regular expressions tutorial (written for Solaris) mentions the limitation.
http://www.grymoire.com/Unix/Regular.html#uh-8
Also
http://www.gnu.org/software/sed/manu...ar-Expressions

leena_d 03-03-2010 04:08 AM

can i increase the length from 255 to 755 or something?

Kenhelm 03-03-2010 07:14 AM

You could try building 755 up in sections using bash arithmetic. I don't know if this will work with all versions of sed. I only have GNU sed, which has an upper limit of 32767 for \{n\}.
Code:

ColNumFrom=755
multiplier=$(( $ColNumFrom / 255 ))  # =2
remainder=$(( $ColNumFrom % 255 ))  # =245
ColNumFromPattern="\(.\{255\}\)\{$multiplier\}.\{$remainder\}"
                                    # =\(.\{255\}\)\{2\}.\{245\}
sed "${RowNum}s@\($ColNumFromPattern\).\{$Diff\}@\1${Data}@" $FILE_NAME >> NewFile


leena_d 03-08-2010 10:20 PM

is there no other way by which a sed command can edit the file beyond 255th character?

pixellany 03-08-2010 10:27 PM

Quote:

Originally Posted by leena_d (Post 3890979)
is there no other way by which a sed command can edit the file beyond 255th character?

I thought that a previous post stated that there was no such limit?? What version of SED are you using?

Note that one post suggests the limitation only as part of the {n} construct--which I assumed to refer to a regex that is repeated n times.

Whatever the limitations actually ARE, you are not going to change them except by:
a. Using a different version
b. Getting the source code and compiling your own special flavor.

ghostdog74 03-08-2010 10:45 PM

Quote:

Originally Posted by leena_d (Post 3883511)

When I run the File for Col 'AA02', it works fine but for Col as 'AB01', is throws following error

sed: Function 2s@\(.\{302\}\).\{4\}@\1 @ cannot be parsed.

Please Help me solve the error...

you are using the wrong tool for the job. You have a csv file where each column is separated by a delimiter(ie comma), its a whole lot easier to split the fields on commas, using tools like awk. (or the shell.)
eg
Code:

echo "Enter The File Name"
read FILE_NAME

echo "Enter The First Column"
read Col

awk -v col="$Col" '
$1==col{
  print "do something to the rest of the fields denoted by $2,$3...etc until $NF"
}
' $FILE_NAME


leena_d 03-15-2010 03:02 AM

in man pages, there is a WARNING

The hold space is limited to 8192 characters.

What does this mean?

konsolebox 03-17-2010 01:57 AM

Quote:

Originally Posted by leena_d (Post 3898695)
in man pages, there is a WARNING

The hold space is limited to 8192 characters.

What does this mean?

How many characters does the pattern in sed matches.. specifically \(.*\)?

leena_d 03-17-2010 11:14 PM

So if this hold space is 8192, & i am trying to edit 2nd row, 302th character (where record/row length = 735 character, so i am editing 1037th character of the file), sed should not through any error.

But i am getting an error that function can't be parsed.

crts 03-18-2010 12:00 AM

Quote:

Originally Posted by leena_d (Post 3902672)
So if this hold space is 8192, & i am trying to edit 2nd row, 302th character (where record/row length = 735 character, so i am editing 1037th character of the file), sed should not through any error.

But i am getting an error that function can't be parsed.

Hi,

the limitations of 255 mentioned earlier refer to the multiplier {} and not to the total buffer-space. Which version of sed are you using?

leena_d 03-18-2010 12:38 AM

i am using sed.
I dont have any other version.:( (ssed GNU sed etc)

I can see the trailer as "HP-UX Release 11i: November 2000" in man pages, bt no version details.


All times are GMT -5. The time now is 07:05 AM.