Computing.Net > Forums > Programming > Problem in sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Problem in sed

Reply to Message Icon

Name: Prosenjit
Date: March 17, 2009 at 05:07:56 Pacific
OS: Unix
Subcategory: General
Comment:

I have a file containing most of the records equal to a length of 193 characters. However some lines are split into 2 lines (surely not to more than 2 lines). Using sed I want to append the next line to all such lines having a length of less than 193 chars so that all lines contain 193 characters. How can I do that ?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 17, 2009 at 10:39:26 Pacific
Reply:

I'm not smart enough with sed to solve this problem. I can probably do it with awk. Let me know if you are interested in that solution.


0

Response Number 2
Name: Prosenjit
Date: March 18, 2009 at 05:56:09 Pacific
Reply:

That will also do. Thanks for the response. Please provide the solution using awk.


0

Response Number 3
Name: nails
Date: March 18, 2009 at 09:25:31 Pacific
Reply:

#!/bin/ksh

# if line is less than 193 characters, append the next line to it

awk ' BEGIN { reclen=193 }
{
if(length($0) < reclen)
  {
  printf("%s", $0)
  getline
  printf("%s\n", $0)
  }
else
  printf("%s\n", $0)

} ' myfile.txt


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


For loop problem again Batch files: Get absolute...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Problem in sed

CDONTS problem in asp www.computing.net/answers/programming/cdonts-problem-in-asp/386.html

Ms Access Password problem in VB6 www.computing.net/answers/programming/ms-access-password-problem-in-vb6/10975.html

my second problem in vb (no. 2) www.computing.net/answers/programming/my-second-problem-in-vb-no-2/4130.html