Re: commands to manipulate files
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Mon, 28 Apr 2008 15:37:38 +0200 (CEST)
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
.
- References:
- commands to manipulate files
- From: Nezhate
- commands to manipulate files
- Prev by Date: Re: commands to manipulate files
- Next by Date: Re: rsync most recent files from large source
- Previous by thread: Re: commands to manipulate files
- Next by thread: Re: commands to manipulate files
- Index(es):
Relevant Pages
|
|