i want to ask how to delete character on specific position in line, lets say i want to remove 5 character from position 1000, so characters from position 1000-1005 will be deleted.
i found this sed command can delete 4 characters from position 10, but i dont know if bigger position or more characters to be delete is needed.
If you are using bash, there is no need to call any external tools to perform this. You can use parameter expansion alone as per below:
# Example line variable
line="this is an example line of text"
# Now lets delete 8 characters after the 10th character (deleting the word example)
echo ${line/${line:10:8}}
You're on the right track. The file size or amount of lines should not matter, imho.
The sed command you mentioned will not work. Here's a fix:
sed "s/\(.\{4031\}\)......./\1/" $filename > $output
Following is even better, just in case, because it means read the first 4031 characters explicitly from the beginning of the line:
sed "s/^\(.\{4031\}\)......./\1/" $filename > $output
Note that the cut command you've posted will delete only 6 characters. To act same as the above sed command it should be:
cut -c -4031,4039- $filename > $output
No matter which command you run, I suggest to test it with only few records of the real data (before you process the whole file) to ensure the output is as expected:
head $filename > temp.data
sed ... temp.data
or
cut ... temp.data
Although both sed and cut work on Ubuntu, the standards only require sed to work on text files. Files with lines containing more than 2048 bytes are not text files on HP-UX. The cut utility, however, is required to work on files with arbitrary line lengths; so it should work on any system.
As RudiC said for sed , the number of lines being processed doesn't matter; both cut and sed work on one line at a time; they don't need to read the whole file into memory at once to do this job.