My requirement is to remove the carriage return in from the lines which i am reading if the length is lesser than 1330 and append the next line with it. Below is the realistic example of file structure.
Input file:
Not sure but the Input_file which you have shown doesn't have any line whose length is more than 1330, so if you are using same Input_file I don't think so it will show any output. You could confirm by doing following too.
awk '{print length($0)}' Input_file
In case no line is having more than 1330 length then you could change the length into above code.
i executed the last command and got 1329 as maximum value in the file.
i edited the command you have given replacing all 1330 with 1329 still no luck.
Thanks
---------- Post updated at 11:57 PM ---------- Previous update was at 11:56 PM ----------
@RudiC hope my last post would have answered you too.
Above code will find out the maximum length into your Input_file and then if any line in Input_file is having lesser length than maximum length value it will print them all together. There could be more terms and conditions but as per your requirement shown I would like to suggest you please try above and let me know how it goes then.
EDIT: Adding a more robust code here, so let's say our Input_file is as follows.
Here I have assumed like if we take maximum length in whole file and then we try merge the lines, there may be a chance while merging lines that they could cross the maximum length as follows we will get while running above code.
Thanks for your reply.
This perl had gave output in a single line and all the in between multiple spaces were shrunken to single space. But i want the original length.
Thanks.
---------- Post updated at 04:55 PM ---------- Previous update was at 04:10 PM ----------
Hi
The first 2 commands did not produce any output, but the 3rd query produced irregular output. Kindly look at the input and output file i attached.
Note: The rule here is the line is not 1329 in length then the next line will be it's missing part. There no scenario of multiple length messages. fixed length will be 1329.
I just changed the 1330 to 1329 in the abv command, looks like the command just added a space in front of the folded line but it did not added it to the previous line. Please find the output file attached. Please find the sample input file in my previous messages.
yielding exactly your desired output.
Please be aware that your sample input file's last line is missing the terminal ^M that all the other lines have.
Thanks for your reply i just ran it for the sample input file it worked well.
But if i mutiply the input records with the same scenario i gave erronous output.please find the attached i/p & o/p file.
There's no ^M chars at EOL any more in the input file, and I don't think the two files in post#16 are correlated. Lines in the output are 2660 chars long...?
EDIT: Got it - due to the missing ^M lines are only 1329 chars. Use that value for comparison and you should come close.