Problem in sed

March 17, 2009 at 05:07:56
Specs: Unix
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 ?

See More: Problem in sed

Report •


#1
March 17, 2009 at 10:39:26
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.

Report •

#2
March 18, 2009 at 05:56:09
That will also do. Thanks for the response. Please provide the solution using awk.

Report •

#3
March 18, 2009 at 09:25:31
#!/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


Report •

Related Solutions


Ask Question