![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| replacing multiple lines with single line | siba.s.nayak | Shell Programming and Scripting | 3 | 05-28-2008 03:43 AM |
| using tr to put multiple lines of output into one line | otes4 | Shell Programming and Scripting | 3 | 02-18-2008 11:30 AM |
| Concatenating multiple lines to one line if match pattern | phixsius | Shell Programming and Scripting | 13 | 01-24-2008 11:02 PM |
| Split a huge line into multiple 120 characters lines with sed? | jerome_1664 | Shell Programming and Scripting | 2 | 08-17-2006 01:03 PM |
| Splitting a single line into multiple lines | thanuman | Shell Programming and Scripting | 4 | 02-23-2005 04:56 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi Guys,
I need a help. I am pretty new to the shell level programing. I was trying to split a long lines to a multiple lines with few conditions. I goggle for the code and found some snippets and tried to modified it but I got few strange problems too. I have to split the lines if line is longer than 120 characters, then I have to separate it by adding "\" at the end of around 120th character. Note it can only separated at delimitation positions such as space or comma. And here is the code for that #!/bin/sh awk '{ if ( length($0) > 120 ) { str=$0 ; i=0 ; while(length(str) > 120) { j=0; for (m=1; m<=120;m++) { letter=substr($0,i+m,1); #printf("%s\n",letter); if( letter !=",") then else { j=m; # printf("%s\n",substr($0,i+1,j) ); } fi if( letter !=" ") then else { j=m;} fi } printf("%s/\n",substr($0,i+1,j) ); i+=j ; str=substr($0,i,length($0) ); } if( length(str) > 1 ) printf("%s\n", substr(str,2,length(str))) ; } else { print $0 } }' myfile.txt But my problem was that above condition is working if put in posted order. If I used to work with equal to and put the expression after then it is not working properly. I was also not able to use the OR expression for comma and space I also need the program which can revert the same operation. I also read few tutorial about sed but found its quite confusing for new users ![]() ![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|