Link to home
Avatar of basirana
basirana

asked on

Shell Script

Hi

I need help to remove first 4 and last 4 lines from file using shell script.
I need another shell script which will find the pattern inside the file and remove the lines.

The lines which got delete will not be saved as spaces in side file.

Can you please with some good example which I can use in my program.

Thanks
Avatar of Tintin
Tintin

Remove first and last 4 lines
#!/bin/sh
sed -e 1,4d -e :a -e '$d;N;2,4ba' -e 'P;D' file >file.new

Open in new window

To remove a pattern
#!/bin/sh
egrep -v "pattern" file >file.new

Open in new window

as the main purpose is only to delete lines, its better to use tail , head and wc than sed for huge files.

head -$(( `wc -l < file` - 4 )) file | tail +4

Open in new window

Avatar of basirana

ASKER

Thanks for your reply it was great help.

The problem is I cant specify the position. I think I haven't asked question properly.

Below are the details.

The below the the patterns inside a file that I want to delete
The patterns like xdp,xfa,xfdf,annots.

I want remove all the lines which are pasted below from a file.
Can you please help How to do this.

Thanks







<?xml version="1.0" encoding="UTF-8" ?> 
<?xfa generator="XFA2_4" APIVersion="2.6.7120.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"
><xfa:data
>
..
..
<HeaderRow xfa:dataNode="dataGroup" /> 
..
..
..
></xfa:data
></xfa:datasets
>
<pdf href="../../../../../../../../DOCUME~1/xml/LOCALS~1/Temp/notes0BDDB2/~6686154.pdf" xmlns="http://ns.adobe.com/xdp/pdf/"
/>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
 <annots /> 
</xfdf>
</xdp:xdp
>

Open in new window

can you also give examples of lines you don't want to delete so that we might see the difference?
The lines which I pasted I want to delte them from the file.
The file contains more then two hundred lines but I pasted only the lines which I have to delete using the shell script.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Thank you