![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| How to split the String based on condition? | sankar reddy | Shell Programming and Scripting | 2 | 03-19-2008 07:48 AM |
| Formatting a text file based on newline and delimiter characters | ntekupal | Shell Programming and Scripting | 5 | 05-11-2007 03:33 PM |
| awk split characters | knc9233 | Shell Programming and Scripting | 1 | 02-19-2007 09:07 PM |
| Split a huge line into multiple 120 characters lines with sed? | jerome_1664 | Shell Programming and Scripting | 2 | 08-17-2006 12:03 PM |
| awk script to split a file based on the condition | superprogrammer | Shell Programming and Scripting | 12 | 06-14-2005 03:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
split based on the number of characters
Hello,
if i have file like this: 010000890306932455804 05306977653873 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC30693599000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011302942311 010000890306946317387 05306977313623 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202010300391748 010000890306945153336 05306977918990 0520080417010521ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011304607230 010000890306948068406 05306977404213 0520080417010523ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202010000717971 010000890306998573372 How can i perform a split based on the number of characters? Foa example i want in array[0] to be stored the 70 first characters of the file and in array[1] the next 70 charactets etc... How can i do this? |
|
||||
|
I know this isn't exactly what you wanted, but this might come in handy -
Code:
split -b 60 filename.txt (It returns files in the format of xaa, xab, xac, xad, etc, each file having the specified number of bytes) Last edited by AndrewTheArt; 07-05-2008 at 09:26 PM.. |
|
||||
|
Quote:
Code:
#!/usr/bin/perl
$teststring = "1234567890abcdefghij0987654321ABCDEFGHIJlmnop";
@chunks = split /(.{10})/, $teststring;
foreach (@chunks) {
printf "%s\n", $_;
}
If you execute this, you get the following: Hostname:> testscript3.sh 1234567890 abcdefghij 0987654321 ABCDEFGHIJ lmnop Hostname:> This is because you have null strings interspersed with the separators. There is no null string before the last 5-character substring because we did not have a full 10 characters to match. I'll leave it for you as an exercise to remove the null strings or otherwise decide how you will skip/ignore them. How exactly you end up incorporating this into your code will also be dependent on your data file. From your description, I could not tell if records spanned lines or not. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|