Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:55:24+00:00 2026-06-05T04:55:24+00:00

I need to split a file into different ones. Exmaple (original file): *****3123123*****RAW text1

  • 0

I need to split a file into different ones.

Exmaple (original file):

*****3123123*****RAW
text1
text2
*****2312354***RAW
text3

Desired output:

[File1.txt]

*****3123123*****RAW    
text1
text2

[File2.txt]

*****312312354***RAW
text3

I tried to use split, but I always get some extra white characters into the array

open FILE, "<file";
@file= <FILE>;
close FILE;
@lines = split (/(RAW\n)/, "@file");
foreach $value (@lines) {
  if ($value =~ /[a-z]|[A-Z]|[1-9]/)  {
    print ("$value\n");
  }
}

Output:

*****3123123*****RAW

 text1
 text2

*****312312354***RAW

 text3

Edit: if I use print (“$value”) instead of print (“$value\n”) this is the output (notice the 1 extra space before the value:

*****3123123*****RAW
 text1
 text2

 *****12354***RAW
 text3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:55:26+00:00Added an answer on June 5, 2026 at 4:55 am

    This program pulls the decimal number from the RAW line and uses it to name the output files. It expects the input file name as a parameter on the command line.

    use strict;
    use warnings;
    
    @ARGV or die "Input file required as command-line parameter\n";
    
    my $out;
    
    while (<>) {
      if ( /(\d+)\*+RAW$/ ) {
        open $out, '>', "$1.out" or die $!;
        select $out;
      }
      print $_ if $out;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to split an flv file into chunks of the known size on
In C# I need to split a string (a log4j log file) into array
I have a file, say 100MB in size. I need to split it into
I have text file with some text information and i need to split this
I've used streamreader to read in a .csv file, then i need to split
I need to split my string input into an array at the commas. Is
I need to split a string into chunks of 2,2,3,3 characters and was able
I have a flat data file that I need to import into my SQL
How do I split a long Perl script into two or more different files
I tried to merge different tab delim files into single file using the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.