Cut bloc from file

Cut bloc from file

Post by owk » Fri, 29 Dec 2000 23:38:03



Hi,

I have file:

aaaaa
bbbbbb
cccccccc
dddddd
.....
begin of blok
....
end of blok
...
eeee
ffffffff

I need file:
begin of blok
....
end of blok

Thanks

 
 
 

Cut bloc from file

Post by Graeme Robinso » Fri, 29 Dec 2000 23:51:02


Hello,

All I can think of is

# 10000 chosen at random
cat <file> | grep -A 10000 "begin of blok" | grep -B 10000 "end of blok"

or

FIRST_LINE=`grep -n "begin of blok" <file> | cut -f1 -d':'`
LAST_LINE=`grep -n "end of blok" <file> | cut -f1 -d':'`
DIFF=`expr ${LAST_LINE} - ${FIRST_LINE}`
cat <file> | head -${LAST_LINE} | tail -${DIFF}

Hope that helps.
Graeme


>Hi,

>I have file:

>aaaaa
>bbbbbb
>cccccccc
>dddddd
>.....
>begin of blok
>....
>end of blok
>...
>eeee
>ffffffff

>I need file:
>begin of blok
>....
>end of blok

>Thanks


 
 
 

Cut bloc from file

Post by T. Kalari » Sat, 30 Dec 2000 00:28:37


This can be accomplished with awk:

awk '/begin of blok/,/end of blok/ {print}' filename


> Hi,

> I have file:

> aaaaa
> bbbbbb
> cccccccc
> dddddd
> .....
> begin of blok
> ....
> end of blok
> ...
> eeee
> ffffffff

> I need file:
> begin of blok
> ....
> end of blok

> Thanks

 
 
 

Cut bloc from file

Post by John Doher » Sat, 30 Dec 2000 03:45:23


| Hi,
|
| I have file:
|
| aaaaa
| bbbbbb
| cccccccc
| dddddd
| .....
| begin of blok
| ....
| end of blok
| ...
| eeee
| ffffffff
|
|
| I need file:
| begin of blok
| ....
| end of blok

Example:

  $ cat foo
  foo
  bar
  baz
  BEGIN
  ...
  ...
  ...
  ...
  END
  qaz
  wsx
  zxc
  $ sed -n '/BEGIN/,/END/p' foo
  BEGIN
  ...
  ...
  ...
  ...
  END
  $

--

 
 
 

Cut bloc from file

Post by Robert Kat » Sat, 30 Dec 2000 04:42:29


Using `sed', you can do this

    $ sed -n '/^begin of blok$/,/^end of blok$/w newfile' file

Using `awk' this will do it:

    $ awk '/^begin of blok$/,/^end of blok$/{print > "newfile"}' file

---Robert

_____________________________

 >
 > Hi,
 >
 > I have file:
 >
 > aaaaa
 > bbbbbb
 > cccccccc
 > dddddd
 > .....
 > begin of blok
 > ....
 > end of blok
 > ...
 > eeee
 > ffffffff
 >
 > I need file:
 > begin of blok
 > ....
 > end of blok
 >
 > Thanks

 
 
 

1. "cutting" a file into smaller files?

I have a 20 MB text file that I want to search through for a certain
string.  

However, when I do a grep - it runs out of memory.  Is there a way to
divide the file into 20 1 MB files so that I can search through it then?  
Is there a better way to deal with this?

Thanks in advance,

Sara

2. need device: devices.pci.b7100010:devices.pci.b7100092

3. Cutting Up A File With Dynamic File Names

4. MOUSEWHEEL SUPPORT?

5. File - How to cut a file block by block ?

6. FSDEXT Problem

7. Help: How to cut last field by CUT command

8. KDevelop: how to create a library ??

9. tcp/ip communication blocs : getmsg hangs

10. How to bloc a web site ???

11. IPTABLES: bloc outgoing traffic individually possible?

12. cut and paste without temp file?

13. Cutting multiple lines from a text file