473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

copying more than one line to another file

When I read file A , it has these lines like that need to be reproduced:



Input a, b, c,

X,Y;



Output m,n

, f,g;



How do I reproduce this in the new file ?

Basically when I read “file A” line by line, I search for first word and if it’s “input” I need to start copying from there till the semicolon appears either in that line or the next line or so.



For a 1 line statement I did the foll: I just need some pointers for a multiline statement.


Expand|Select|Wrap|Line Numbers
  1. while ($line = <$inFP>) {
  2.  
  3. my (@tmp) = split (/\s+/, $line);
  4.  
  5.  if (($tmp[0] eq "output") && ($tmp[-1] =~ /;$/)) {
  6.  
  7.   print outFP "$line\n";
  8.  
  9.  }
  10.  
  11. }
  12.  
Dec 17 '08 #1
2 1913
KevinADC
4,059 Expert 2GB
as posted on other forum:

Expand|Select|Wrap|Line Numbers
  1. while ($line = <DATA>) {  
  2.    if ($line =~ /^(Input|Output)/) { 
  3.       print $line; 
  4.       while ($line = <DATA>) { 
  5.          if ($line =~ /;\s*$/) { 
  6.             print $line; 
  7.             last; 
  8.          } 
  9.          print $line; 
  10.       } 
  11.    } 
  12. __DATA__ 
  13. Input a, b, c,  
  14. stuff here 
  15. X,Y;  
  16.  
  17. test test 
  18.  
  19. Output m,n  
  20. stuff here 
  21. , f,g; 
  22.  
  23. test test
  24.  
if the semi-colon really is the last thing before the line ending you can remove \s* in this regexp:

Expand|Select|Wrap|Line Numbers
  1. if ($line =~ /;\s*$/) {
Dec 17 '08 #2
Appreciate the help offered.Also for trying to correct my ways in the other forum.
Dec 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
2
by: Peter Sands | last post by:
Hi, I am testing out some restores to a stand-by server, by roll-forwading the logs. I have this setup. There is no user-exit, but logretain is on, for archive logging. I have 2 DB's on...
4
by: Lafer | last post by:
Hello, I am attempting to write a terminal interface program using PowerPC Assembly/C, where I am using an integer-to-ASCII conversion algorithm. Unfortunately, I have run into some difficulties...
11
by: Geoff | last post by:
Hi I have a DataTable with thousands of rows. I want a quick way to insert the rows into a table in an Access database with the same structure. I have been using an update command but found it...
1
by: --Fragman-- | last post by:
Hello all, I'm creating some kind of object oriented drawing program, my classes consist of points, lines, quads, etc... Right now I'm implementing undo/redo and copy/paste functionality. For...
6
by: Jim Heavey | last post by:
I have written a little application which copies files from one location to another location. Before it copies the file, it ensure the directory for both the from and to locations is valid. It...
8
by: Jared Wiltshire | last post by:
Hi, I've written the following code to copy one files contents line by line into another file. However I'm a bit dubious about using the infinite loop to do this. ifstream infile("File1.txt");...
9
by: Jess | last post by:
Hello, I tried to clear a vector "v" using "v.clear()". If "v" contains those objects that are non-built-in (e.g. string), then "clear()" can indeed remove all contents. However, if "v"...
13
by: writeson | last post by:
Hi all, I'm writing some code that monitors a directory for the appearance of files from a workflow. When those files appear I write a command file to a device that tells the device how to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.