?
Solved

strip and keep the first five data inputs

Posted on 2007-03-26
5
Medium Priority
?
242 Views
Last Modified: 2010-03-05
Hi all

I would like to strip and keep the first five data inputs. The array length may vary then sample.

array Input: |data1|data2|data3|data4|data5|data6|data7|data8|data9|data10|data11

Result: data1|data2|data3|data4|data5

0
Comment
Question by:blnukem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18794824
perl -lpe 's/\|*(([^|]*\|){4}[^|]*).*/$1/'
0
 
LVL 1

Accepted Solution

by:
midrisi earned 1000 total points
ID: 18795104
Below code snippet will do what you like.This array can be expanded also.

@array=("data1","data2","data3","data4","data5","data6","data7","data8","data9","data10");

foreach $res (0..4)
{
        push(@result,$array[$res]);
}
print @result;
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 1000 total points
ID: 18795168
@result=@array[0..4];
0
 
LVL 1

Expert Comment

by:midrisi
ID: 18795362
So modified code is

@array=("data1","data2","data3","data4","data5","data6","data7","data8","data9","data10");

@result=@array[0..4];

print @result;
0
 
LVL 84

Expert Comment

by:ozo
ID: 18795416
I thought you wanted to print "data1|data2|data3|data4|data5" given input "|data1|data2|data3|data4|data5|data6|data7|data8|data9|data10|data11"
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question