Re: commands to manipulate files



2008-04-28, 06:07(-07), Nezhate:
Hi all,
I'm writing a small shell program that takes a file as input and print
result in another file.
I'm searching for command that can extract data which is between two
asterisks.
The next file shows what I mean:

-----------------------------------
in this file *I want to print only this* and *this*
Linux is the *best operating* system!
end of *this* file
-----------------------------------------

It's clear that a search for character * must be done in each line
contained in file , when reached, data is written in the another file
until it reaches the second asterisk, then it stops to write data and
pass to the next line and so on.

awk -F'[*]' 'NF>2 {for (i = 1; i < int((NF+1)/2); i++) print $(i*2)}'

or:

perl -lne 'print for /\*(.*?)\*/g'

or

sed -n 's/[^*]*\*\([^*]*\)\*/\1\
/g; s/\(.*\)\n.*/\1/p'


--
Stéphane
.



Relevant Pages

  • Re: commands to manipulate files
    ... I'm searching for command that can extract data which is between two ... until it reaches the second asterisk, then it stops to write data and ... nonstandard features. ...
    (comp.unix.shell)
  • Re: commands to manipulate files
    ... I'm searching for command that can extract data which is between two ... until it reaches the second asterisk, then it stops to write data and ...
    (comp.unix.shell)
  • commands to manipulate files
    ... I'm searching for command that can extract data which is between two ... until it reaches the second asterisk, then it stops to write data and ...
    (comp.unix.shell)
  • Re: -crawl- YANI for lua scripts.
    ... Why not let player assign two pieces of julery in his ... command to quick-change amulets and one of them will be on my neck -> script ... >> - Defining useful but complex conditions for searching though ingame ... names of text files with lists of searched objects). ...
    (rec.games.roguelike.misc)
  • Re: Can I mimic a btn_Click() ?
    ... In the sample code instead of searching an event with type of ... Other remote UDP command are> OK as long as the display is not affected. ... Once I'm in the> CalibrateLCD_Clickevent handler my sender and "this" look OK in my> "Autos" window in both cases. ...
    (microsoft.public.dotnet.framework.compactframework)