sed 255 Character Limitation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed 255 Character Limitation
# 1  
Old 01-11-2016
sed 255 Character Limitation

Hello,

I am using sed command to place a comma dynamically in certain positions. When the position variable exceeds 255 characters, it errors out. I would appreciate if someone can point in the correct direction

Code:
sed 's/^\(.\{'"$pos"'\}\)./\1,/' ragha.txt > ragha3.txt

If $pos > 255, it errors out with cannot parse.
# 2  
Old 01-11-2016
Quote:
Originally Posted by ragha81
If $pos > 255, it errors out with cannot parse.
Care to tell us which OS (to be precise: which sed) you use?

bakunin
# 3  
Old 01-12-2016
Use perl:
Code:
pos=390
perl -pe 's/^(.{'"$pos"'})./$1,/' ragha.txt

# 4  
Old 01-12-2016
Hi Bakunin,

We are using HP -UX Operating System.

MadiinGermany.. Unfortunately perl is not installed in our system.

Thanks,
Ragha
# 5  
Old 01-12-2016
Try with awk
Code:
awk -v pos=390 '{print substr($0,1,pos) "," substr($0,pos+1)}' ragha.txt

# 6  
Old 01-12-2016
Quote:
Originally Posted by ragha81
We are using HP -UX Operating System.
The limitation is common to all "regular" sed variants, AIX-sed and Solaris-sed do the same. It is not possible to use ranges bigger than 255 constructs with curly braces ("\{xx\}"). Maybe Don Cragun can shed more light on what the standards prescribe on the behavior of sed.

One possbility is to use two such ranges, like this:

Code:
sed 's/^.\{255\}.\{25\}//' file

but i have to admit this is cumbersome and a workaround at best, certainly not a solution. Other than using one of the other text filters (perl, awk, ... like MadeInGermany suggested) there is maybe GNU-sed, which might not have the limitation. Alas i don't know for sure, you will have to try that out on the next Linux system you find lying around.

I hope this helps.

bakunin
# 7  
Old 01-12-2016
Quote:
Originally Posted by bakunin
The limitation is common to all "regular" sed variants, AIX-sed and Solaris-sed do the same. It is not possible to use ranges bigger than 255 constructs with curly braces ("\{xx\}"). Maybe Don Cragun can shed more light on what the standards prescribe on the behavior of sed.

One possbility is to use two such ranges, like this:

Code:
sed 's/^.\{255\}.\{25\}//' file

but i have to admit this is cumbersome and a workaround at best, certainly not a solution. Other than using one of the other text filters (perl, awk, ... like MadeInGermany suggested) there is maybe GNU-sed, which might not have the limitation. Alas i don't know for sure, you will have to try that out on the next Linux system you find lying around.

I hope this helps.

bakunin
To replace the 391st character I think that would be:
Code:
sed 's/^\(.\{255\}.\{135\}\)./\1,/' file

The standards say that systems must allow RE_DUP_MAX repeated occurrences of a BRE or ERE in an interval expression and that RE_DUP_MAX but be at least _POSIX_RE_DUP_MAX which is defined by the current standards to be 255. (This is for all BREs and EREs; not just BREs used in sed.) You can find the values of RE_DUP_MAX and _POSIX_RE_DUP_MAX on your system with:
Code:
getconf _POSIX_RE_DUP_MAX;getconf RE_DUP_MAX

If the awk suggestion provided by MadeInGermany in post #5 in this thread is not acceptable, one could write a shell function to generate the BRE to be used by sed when given $pos as an operand changing:
Code:
sed 's/^\(.\{'"$pos"'\}\)./\1,/' ragha.txt > ragha3.txt

to:
Code:
sed 's/^\('"$(func_name "$pos")"'\)./\1,/' raga.txt > ragha3.txt

to get a BRE using as many interval expressions as are needed (remembering, of course, that sed also has a maximum line length limit (LINE_MAX)).
These 2 Users Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

3. Shell Programming and Scripting

Ignore the 255 character limit of command line

Hi I would just like to ask if there is a way for UNIX to ignore/overcome the 255 character limit of the command line? My problem is that I have a really long line of text from a file (300+ bytes) which i have to "echo" and process by adding commands like "sed" to the end of the line, like... (5 Replies)
Discussion started by: agentgrecko
5 Replies

4. Shell Programming and Scripting

SED on AIX Limitation

Hello, I have a problem running a script created in ksh for Linux (Tested on Debian 5.0, Ubuntu Server 10.04 and RHEL 5.1), it works properly. :b: I trying to pass it to a AIX 5.3. :wall: The problem is the character limit of 256 on a command system and SED. I need to cut the contents of... (8 Replies)
Discussion started by: nemesis.spa
8 Replies

5. Shell Programming and Scripting

echo !SR | nc 255.255.2.2 80 - how to in XP?

Hi guys I am trying to interface with an old industrial scanner through an old PC with an old network card and a copy of Linux. It now needs to speak to a Windows XP machine, but I have no idea what the Windows equivalent of these functions would are: echo !1 | nc 255.255.2.2 80 echo ?2 | nc... (3 Replies)
Discussion started by: TonyG
3 Replies

6. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

7. Shell Programming and Scripting

Character limitation in Join command

Hi, I'm trying to compare and join two files using join command. One of my files length is 3000. Join is not working for this file. It truncates character after 1600 lines. Anyone know a solution for this? the command i used is Comparing the 1st column of the first file and 3rd column of... (1 Reply)
Discussion started by: gpaulose
1 Replies

8. UNIX for Dummies Questions & Answers

SED: Can't Repeat Search Character in SED Output

I'm not sure if the problem I'm seeing is an artifact of sed or simply a beginner's mistake. Here's the problem: I want to add a zero-width space following each underscore between XML tags. For example, if I had the following xml: <MY_BIG_TAG>This_is_a_test</MY_BIG_TAG> It should look like... (8 Replies)
Discussion started by: rhetoric101
8 Replies

9. Shell Programming and Scripting

sed limitation of 255 characters

Gurus, sed -e "s/\(.\{1,255\}\)\(.\{1,2\}\)\(.*\)/\1AB\3/" FILE ---this works sed -e "s/\(.\{1,468\}\)\(.\{1,2\}\)\(.*\)/\1AB\3/" FILE ---this does not It works only till 1,255 ( any number below 255 works) Any one know how to increase this limit. Thanks Sirababu (4 Replies)
Discussion started by: sirababu
4 Replies

10. HP-UX

HP-UX 11i - File Size Limitation And Number Of Folders Limitation

Hi All, Can anyone please clarify me the following questions: 1. Is there any file size limitation in HP-UX 11i, that I can able to create upto certain size of file (say 2 GB) and not more then that???? 2. At max. how many files we can able to keep inside a folder???? 3. How many... (2 Replies)
Discussion started by: sundeep_mohanty
2 Replies
Login or Register to Ask a Question