The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Append to front of newline
Discuss Append to front of newline in the Regex Programming forum on Dev Shed. Append to front of newline Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 4th, 2011, 08:18 AM
|
 |
cave painting, the 1st Opn Src
|
|
Join Date: Jun 2003
Posts: 532
Time spent in forums: 1 Day 16 h 3 m 34 sec
Reputation Power: 0
|
|
|
Append to front of newline
Code:
################ PATCH 4487 file activity summary ##########
psrc/146.rpt 6 7 Yes Yes
psrc/146.scr 12.1.6 12.1.8 Yes Yes
psrc/146PD 22.1.13 22.1.15 Yes Yes
############## PATCH 5642.42 file activity summary #######
psrc/146.rpt 7 8 Yes Yes
psrc/146.scr 12.1.8 12.1.9 Yes Yes
psrc/146PD 22.1.15 22.1.20 Yes Yes
############## PATCH 6412.22 file activity summary #######
psrc/146.rpt 8 9 Yes Yes
psrc/146.scr 12.1.9 12.2.0 Yes Yes
psrc/146PD 22.1.20 22.1.21 Yes Yes
output desired
6412.22,psrc/146.rpt,8,9,Yes,Yes
6412.22,psrc/146.scr,12.1.9,12.2.0,Yes,Yes
6412.22,psrc/146PD,22.1.20,22.1.21,Yes,Yes
I need to figure out how to pull the Patch number from the first line starting with ####, and pre-pend it to the patch line, ie: prsrc/145.rpt...
Once I do that I can strip the \t in file and get it into a prepped for insert into the table.
How can I get achieve getting the changing patch number and add it to the patch output line?
__________________
Curious by Nature,
Linux by Choice
Lawson ERP reference tools: Lawsuss.com
|

August 4th, 2011, 10:45 AM
|
|
|
|
Please show your own approaches and their results first. Reading your latest posts, I get the feeling, you're just letting us do your work without any own efforts.
Regards, Jens
|

August 4th, 2011, 12:42 PM
|
 |
cave painting, the 1st Opn Src
|
|
Join Date: Jun 2003
Posts: 532
Time spent in forums: 1 Day 16 h 3 m 34 sec
Reputation Power: 0
|
|
I think that is a little unfair that you want to decide whether or not this forum should help me because you think I am asking to many questions or the wrong type of request.
I've posted a few questions in the last week while working thru some new code ideas and asking for syntax help.
I try to post sample snippets, current results and desired results. If I post a portion of the problem, you don't see the other 70-80% of the problem that I've already fixed. And, 95% of the time I've already Google'd or visited php.net to look for an answer.
If you look at this question I don't ask a multiple part questions, I ask for help trying to tackle the first step in this process. That is not asking you do to my work, I'm asking someone for possible ways to solve this problem. If you can help, then please post an answer or post a link because I have no idea how to pull a piece of a string out of a file and pre-append it to the next line in the file.
And note, the detail of this post is the overall outcome, I in NO WAY asked for a complete answer, I asked Quote: | how to pull the Patch number from the first line starting with ####, and pre-pend it to the patch line | . That is 1 request for help. And I noted Quote: | Once I do that I can strip the \t in file and get it into a prepped for insert into the table. | , the follow on steps that I had in mind for this question.
Answer if you want, Plonk if you want, but unless you have the authority to ban me for asking for help I'm going to ask you to keep your comments to yourself.
Thanks!
|

August 4th, 2011, 03:05 PM
|
|
|
Quote: | Originally Posted by dba_frog Answer if you want, Plonk if you want, but unless you have the authority to ban me for asking for help I'm going to ask you to keep your comments to yourself |
Sorry, but that's a luxury you don't get after continuously ignoring the "How to ask smart questions" guide. You've reached a point, where I'm seriously doubting, I really want to answer your question, since I'm getting the expression, you don't learn from previous answers. The reason why I get this impression is, because you're repeatedly asking very very basic questions without any obvious effort on your part.
That said, let me give you some pointers in the right direction, afterwards the rest is up to you:
- You'll need to deal with your input line by line.
- You'll have to decide what to do, depending on the beginning of your line.
- You're looking for an algorithm, not for a regular expression, since a single regular expression cannot solve your problem.
- Whenever you encounter a new patch set information, store the version info somewhere.
- Whenever you encounter a new file, use its data together with the stored information from the new patch set header.
- Forget the thing with stripping the tabs. Use them as a delimiter, when parsing your file info line.
Regards, Jens
|

August 8th, 2011, 10:06 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
You've dealt with loops and arrays in PHP before, as I can see from the various arguments you've had on the topic with our long-standing members.
Jens' advice is correct. Loop line by line. If the line starts with ###, replace the stored prepend number. If not, re-format the line with the prepend number.
The new user guide (which contains information on asking good questions and proper forum etiquette) is right below this message. Yes, you've been on the forums for a while, but you're very combative and this question was pretty much "this is what I start with, this is how I want it to end up, please help." YOU may understand that this is a small set of an overall problem and you're only giving us 10% of it, but we don't. Your answer is "this is not a regular expression question, this is a file parsing question, parse it line by line."
Which language are you familiar with? You've posted in both Perl and PHP. I will move this thread to the appropriate forum for you based on how you'd like to solve it.
-Dan
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|