Text editor with search and capture
Hello all
i was wondering if in all the editors/tools in linux, if there was a prog that can extract a portion of a text file, giving it a starting line of say o as the first character on a line of say o35565 oxxxxx then when it finds the next line down the file with the same thing oxxxxwhatever it could take those lines and all the lines between them and save it to another file? i dont know if you call this parsing? or what. can anybody help? Thank you Tappm |
Sounds like what you are wanting is a tool such as AWK or SED, rather than a text editor. If you have no need to actually open the file and look at it yourself, or edit it a typical "text editor" context, then please (use Google) read about GNU Sed, and GNU AWK (on Linux, this is called "gawk"), and decide if either of these tools sounds like the thing you need.
Let us know what you learn. Kind regards. |
Thanks for the input
i'll look at those. what the problem is exactly is on my CNC machines at work i have the ability to save all my part cutting programs into one large file, because saving them individually would take along time. so the single file appends on after the other into a large txt file, at the beginning of a program the first line is the prog no. with the format o354444(description of program) course the o is the only constant there as the prog files all have a different no. Then at the start of the next file is the same thing o354433(description of program) so if the needed program could search and output these into individual files, it would be a great tool. Thankyou again |
Gotcha now, I understand. These are a whole whack of NC programs, all concatenated into one long file. You want to use a tool to split the big file, so that each invidual NC program is its own file. Geez, are CNC machines still that frikkin slow at uploading their data? Sounds like it hasn't improved since ~1996 when I was doing the same thing. Or is it just the time to locate and save each file individually by hand, that takes up the time?
Anyhow, yes, AWK would be a good tool. Or, since the task is not super complicated, you could likely do this using just bash shell too. Either way, you'll want to tell us what sort of PC you will be running this program on - Windows or Linux? If Linux, which Distro and version is it? Sometimes this makes a difference. Also, if you will be needing help writing a bash script or AWK program to do this job,, LQ members will expect a couple things: 1) Post (inside code tags please) a chunk of the long file so we can see precisely what the data looks like. The chunk you show should include at least one whole NC program, and a couple lines above and below it. 2) members will generally expect you to do research and development of your own code, on your own, to some extent. We love to help, but we also really like when the helpee takes an active role. 3) This *sounds* like an easy task, and if so, a lot of R+D will not be required. If it's as easy as I hope and believe it will be, it should take no more than a few to maybe a dozen lines of code. BUT - until we see the data, I am speculating a lot here.. |
With luck, this could be a simple one-liner. Look in the file for character sequences that delimit the sections you want to break out of the overall file. These can be record delimiters for things like AWK and Perl. If you can concisely define record delimiters, then you can get Perl or AWK write out each record to a file.
--- rod. |
1 Attachment(s)
Thanks alot for your help
it would be more a bit easier to use the windows xp box I use at work but if i need to i could bring my laptop SUSE v6/windows dual boot box to do it with Here is an old == small file of a complete all files save, couple years old the newest ones are a couple megs seeing as how ive never used awk, yes i could use some help with wielding that prog thank you again |
Hello TAPPM and welcome to LQ (EDIT: oh sorry you're not new here... ;) ),
I don't know if this helps, the editor vim has a feature named "folding". It is useful to hide parts of a file. Vim is available for both, Linux and Windows and I'm using it very often with Windows. You can install it as an executable on a USB-drive and use it with every Windows-PC.... well, enough of the Windows stuff ;) You may look here: http://vimdoc.sourceforge.net/htmldo...l#fold-methods or here http://vim.wikia.com/wiki/Folding but there is much further documentation. Markus |
Something like this may (closely enough) resemble what you're after?
Code:
awk 'BEGIN{ Cheers, Tink |
@ Tink,
It looks lovely. :) One thing though: the ^O should be an ^o (lowercase oh) -- assuming not a typo on OP's part. |
Quote:
;) Cheers, Tink |
Quote:
Of course.. Why didn't I think of that? :/ Cheerios! EDIT: By the way, here's what I was initially thinking of, using bash rather than awk: Code:
#!/bin/bash Note that the script will erase & re-create any output file that finds to be pre-existing. |
downloaded a copy of gawk , it installed but will not run on this windows box
kinda strange, installed to all programs menu but only shows doc/pdf files no executable tried to run it from a dos window, no luck. any ideas? Thank you |
Chances are you'll need to modify the PATH to include its
directory, and run it from the command line (as there's no GUI awk to the best of my knowledge). And since this obviously isn't a Linux question after all I'm moving it to <PROGRAMMING>. Cheers, Tink |
Quote:
In case it helps, it appears to me that you should have gotten your gawk for Windows from here: http://sourceforge.net/projects/gnuwin32/files/gawk/ Is that what you used? If not, please link to where/what you downloaded. Until you have a working gawk (or awk or bash) on your Win, that's as much as I can help. Maybe you could use a Linux liveCD if this Windows method continues to be pesky? Or, just get access to a Linux machine and do this there. |
|
Cygwin is definitely the way to go.
|
ok i drove home and got my linux boxette (laptop) and suse 9, not 6 cd's to load it onto one of my computers here at work,
let's see how this goes. i started using linux (redhat i think it was) around 1995 installed and played with alot of them rehat mandrake suse freeb but since i got this new job 4 years ago, i havent had time to play with it . needless to say ive forgotten how to do alot of things in a shell like write a script to run the code you have posted. but here goes thanks for your help |
While I haven't used the standalone executable of AWK in
Windows, I helped a colleague install GNU grep, and it works OK. As you noted, the installer doesn't do much (sensible stuff anyway). But the executables can be used, none the less. Cheers, Tink |
wow alot ive forgotten about linux
|
All times are GMT -5. The time now is 03:10 PM. |