|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Remove certain lines from file based on start of line except beginning and ending
Hi, I have multiple large files which consist of the below format:
Quote:
Any help would be greatly appreciated. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Is this what you want...? Code:
awk 'NR==1
s=0
NR>1 && !/^00/
/^00/{s=1}
END{if(s){print}}' file |
| The Following User Says Thank You to pamu For This Useful Post: | ||
nwalsh88 (02-20-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks for your reply.
Yes that is along the lines of what i need. That script removes the 00 records except the 1st I also need it to remove all the 80 records but leave the last one as it is. Any ideas....? |
|
#4
|
|||
|
|||
|
Quote:
try Code:
awk 'NR==1
s=0
NR>1 && !/^00|^80/
/^80/{s=1}
END{if(s){print}}' file |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
It's getting there now
That edit to the script removes all the 80 records including the last one. How could i get it to leave the last 80 record there?? |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Try now Code:
awk '!s && /00/{s=1;print}
/80/ && a{K=$0;for(i=1;i<=a;i++){print X[i]};a=0}
!/^00|80/{X[++a]=$0}
END{if(K){print K}
for(i=1;i<=a;i++){print X[i]}
}' file |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Same again pamu
Everything is perfect apart from the final line of the file which should be the 80 record but is the 70 record |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| join based on line number when one file is missing lines | jackiev | Shell Programming and Scripting | 1 | 06-27-2011 07:08 PM |
| how to remove lines ending with '*' | jdhahbi | UNIX for Dummies Questions & Answers | 7 | 11-09-2010 09:43 AM |
| How to fetch rows based on line numbers or based on the beginning of a word? | Muthuraj K | Shell Programming and Scripting | 18 | 02-02-2010 04:27 AM |
| Remove lines based on contents of another file | bashshadow1979 | Shell Programming and Scripting | 4 | 03-25-2009 12:32 PM |
| Remove white space at the beginning of lines | tipi | Shell Programming and Scripting | 4 | 09-02-2008 03:35 PM |
|
|