Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Conditional newline removal:
I have a requirement as follow:
To remove the newline characters for a fixed width length file of 20 chars.
for example:
cat 1.txt
1234567890
1234567890
09876543210987654321the output should be:
12345678901234567890
09876543210987654321The first line should join the second line due to it not reaches the width of 20 chars. After it reaches 20 chars, it should be a new line. The idea is to remove the newline char when in between text.
Any solution?
Thanks in advance

A partial reply...
This will remove the NL character.
sed 'N;s/\n//' datafile
therefore
1234567890
1234567890becomes
12345678901234567890This will print lines of less than 21 chars and simply ignores those lines that are longer:
sed -n '/^.\{21\}/!p'

Thanks for the partial reply though it may not be a final one...
i got your idea but it seems it is really hard to combine the two sed command to get it done in one step, isn't it? I had been thinking for a long time also...
anyways, thanks for the partial solution, appreciate that!

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |