07-23-2012
Does the line always have 1000 characters? What should the program do if there are less/more than 1000 chars?
10 More Discussions You Might Find Interesting
1. Programming
Good morning,
I would like to make a little interface for an application which will split the console in 2 "parts":
1 top area to print messages & 1 command prompt.
The printed messages are asynchronous to the command prompt, what I mean is that while while the user types a command a... (2 Replies)
Discussion started by: jonas.gabriel
2 Replies
2. Shell Programming and Scripting
Hi,
I need to split xml-files with sizes greater than 2 gb into smaler chunks. As I dont want to end up with billions of files, I want those splitted files to have configurable sizes like 250 MB. Each file should be well formed having an exact copy of the header (and footer as the closing of the... (0 Replies)
Discussion started by: Malapha
0 Replies
3. Shell Programming and Scripting
Hi all,
I want to split a string in awk and treat each component seperatley.
I know i can use:
split ("hi all", a, " ")
to put each delimited component into array a.
However when i want to do this with just a string of chars it does not work
split ("hi", a, "");
print a;
prints... (6 Replies)
Discussion started by: pxy2d1
6 Replies
4. Shell Programming and Scripting
How do I split a file into many parts but with different amounts of lines per part? I looked at the split command but that only splits evenly.
I'd like a range specified to determine how many lines each output file should have.
For example, if the input file has 1000 lines and the range is... (1 Reply)
Discussion started by: revax
1 Replies
5. UNIX for Dummies Questions & Answers
I have an input file of this format
<Date><other data>
For example,
20081213aaaaaaaaa
20081213bbbbbbbbb
20081220ccccccccc
20081220ddddddddd
20081220eeeeeeeee
20081227ffffffffffffff
The first 8 chars are date in YYYYMMDD formT. I need to split this file into n files where n is the... (9 Replies)
Discussion started by: paruthiveeran
9 Replies
6. Shell Programming and Scripting
Input:
Debris Linux is a minimalist, desktop-oriented distribution and live CD based on Ubuntu.
It includes the GNOME desktop and a small set of popular desktop applications, such
as GNOME Office, Firefox web browser, Pidgin instant messenger, and ufw firewall manager.
Debris Linux ships... (5 Replies)
Discussion started by: cola
5 Replies
7. Shell Programming and Scripting
input
-200 2.4
0 2.6
30 2.8
output
-500 0
-499 0
-488 0
..........
..........
....
-200 2.4
....
...
0 2.6 (6 Replies)
Discussion started by: quincyjones
6 Replies
8. Shell Programming and Scripting
Hi there,
I have an output from a command like this
# ypcat -k netgroup.byuser| grep steven
steven.* users_main,users_sysadmin,users_global,users_backup_team
and wanted to pull the 'users' netgroups returned into a perl array, that will look like this
users_main... (2 Replies)
Discussion started by: rethink
2 Replies
9. Shell Programming and Scripting
Hi Experts.
I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file.
awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename
sample data
1,abc,def,1234,A *
2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies
10. Shell Programming and Scripting
I have the string:
XXXX.YYYY_ZZZ.20180724.01.txt
I need to get rid of .txt and get full four parts
XXXX.YYYY_ZZZ.20180724.01
I did:
CTL=`echo XXXX.YYYY_ZZZ.20180724.01.txt | rev | cut -d"." -f4 | rev`
But got only YYYY_ZZZ
What should I do to get all four parts of that... (4 Replies)
Discussion started by: digioleg54
4 Replies
LEARN ABOUT PHP
preg_split
PREG_SPLIT(3) 1 PREG_SPLIT(3)
preg_split - Split string by a regular expression
SYNOPSIS
array preg_split (string $pattern, string $subject, [int $limit = -1], [int $flags])
DESCRIPTION
Split the given string by a regular expression.
PARAMETERS
o $pattern
- The pattern to search for, as a string.
o $subject
- The input string.
o $limit
- If specified, then only substrings up to $limit are returned with the rest of the string being placed in the last substring. A
$limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the $flags parameter.
o $flags
-$flags can be any combination of the following flags (combined with the | bitwise operator):
o PREG_SPLIT_NO_EMPTY - If this flag is set, only non-empty pieces will be returned by preg_split(3).
o PREG_SPLIT_DELIM_CAPTURE - If this flag is set, parenthesized expression in the delimiter pattern will be captured and
returned as well.
o PREG_SPLIT_OFFSET_CAPTURE - If this flag is set, for every occurring match the appendant string offset will also be
returned. Note that this changes the return value in an array where every element is an array consisting of the matched
string at offset 0 and its string offset into $subject at offset 1.
RETURN VALUES
Returns an array containing substrings of $subject split along boundaries matched by $pattern.
EXAMPLES
Example #1
preg_split(3) example : Get the parts of a search string
<?php
// split the phrase by any number of commas or space characters,
// which include " ",
, ,
and f
$keywords = preg_split("/[s,]+/", "hypertext language, programming");
print_r($keywords);
?>
The above example will output:
Array
(
[0] => hypertext
[1] => language
[2] => programming
)
Example #2
Splitting a string into component characters
<?php
$str = 'string';
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
print_r($chars);
?>
The above example will output:
Array
(
[0] => s
[1] => t
[2] => r
[3] => i
[4] => n
[5] => g
)
Example #3
Splitting a string into matches and their offsets
<?php
$str = 'hypertext language programming';
$chars = preg_split('/ /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
print_r($chars);
?>
The above example will output:
Array
(
[0] => Array
(
[0] => hypertext
[1] => 0
)
[1] => Array
(
[0] => language
[1] => 10
)
[2] => Array
(
[0] => programming
[1] => 19
)
)
NOTES
Tip
If you don't need the power of regular expressions, you can choose faster (albeit simpler) alternatives like explode(3) or
str_split(3).
Tip
If matching fails, an array with a single element containing the input string will be returned.
SEE ALSO
PCRE Patterns, preg_quote(3), implode(3), preg_match(3), preg_match_all(3), preg_replace(3), preg_last_error(3).
PHP Documentation Group PREG_SPLIT(3)