Delete last two line inbetween pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete last two line inbetween pattern
# 1  
Old 10-24-2013
Delete last two line inbetween pattern

Hi
I had the text file as below and i wand to keep only 4 lines from tag :7023: to next : (i.e new tag start) including tag lines. any solution ?
Code:
:7023:TEST LINE NUMBER
 1101010021442 TESTING
 HI HERE 
PLEASE HELP ME OUT
AC 20101906523 
:7028:OUR


Last edited by Franklin52; 10-24-2013 at 10:11 AM.. Reason: Please use code tags
# 2  
Old 10-24-2013
Quote:
Originally Posted by sandipgawale
HiI had the text file as below and i wand to keep only 4 lines from tag ":7023:" to next ":"(i.e new tag start) including tag line . any solution ?:7023:TEST LINE NUMBER 1101010021442 ESTING HI HEREPLEASE HELP ME OUTAC 20101906523 :7028:OUR
Please Use codetag and show us your expected output
# 3  
Old 10-24-2013
Code:
cat file
some data
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523
:7028:OUR
some more data

Code:
awk '/^:[0-9]+:/ {f=0} /^:7023:/ {f=1} f' file
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523

# 4  
Old 10-24-2013
ya but i want only 4 lines from tag :7023: to next :.
all the lines after line number 4 should get delete till the next tag start i.e., :
so i want the output as

Code:
some data
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
:7028:OUR
some more data


Last edited by Don Cragun; 10-24-2013 at 11:14 AM.. Reason: Add CODE tags.
# 5  
Old 10-24-2013
Your requirements are ambiguous and the output that you say should be produced does not match the sample input you provided. You say that:
Code:
some data

should appear at the start of your output, but it did not appear in you input??? Are we supposed to produce random data when we see a line starting with a colon? Or are we supposed to always output the line:
Code:
some data

at the start of the output?

Do you want the 1st four lines of each section that starts with a line containing a colon?

After inventing "some data", do you want all lines in the file except for lines five and on when you find a line starting with :7023: and restart printing everything when you find the next line starting with a colon?

Please give us a clear statement of what you are trying to do, a clear sample input file (in CODE tags), and a clear sample output file (in CODE tags) that shows what you want done to the given sample input. Have you sample input contain at least two complete groups of lines that start with a colon.
# 6  
Old 10-24-2013
@sandipgawale
You want the tag printed or not.
My output was:
Code:
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523

And not the input I provided.

Give an example on how output should look like?
# 7  
Old 10-24-2013
Hi,
Try this (already see in another post Smilie ):
Code:
sed -n '/^:[0-9]*:/{$!N;$!N;$!N;p;}' file

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

2. Shell Programming and Scripting

Delete line contains pattern

Hi all, I'm trying to delete line contains pattern from file using ex editor I have tried something like this user@host ~ $/usr/bin/echo "/$pattern/d\nwq!"| /usr/bin/ex -s file.txt This line is from script but it doesn't work any idea (4 Replies)
Discussion started by: h@foorsa.biz
4 Replies

3. Shell Programming and Scripting

delete next line of the given pattern

How to delete the next lines of the below pattern matches a certain criteria using sed it is rainy heavily<name> <name> how is it there <name> gfhafje qwfwfqw eeqewqrt <name> there is heavy raining <name> so that the output will be it is rainy heavily<name> gfhafje qwfwfqw... (2 Replies)
Discussion started by: tkmmelvin
2 Replies

4. Homework & Coursework Questions

delete line containing a pattern!!!

if the given pattern exists in the file with the very next line starting and ending with the same pattern , delete the line that starts and ends with the given pattern. So upon running on this file ===================== hai people<PATTERN> we had <PATTERN>a lot of fun<PATTERN> ... (1 Reply)
Discussion started by: jacky29
1 Replies

5. Shell Programming and Scripting

delete line after pattern

Hi, Before insert, delete everything. If ' available before insert, then we need to keep this. Input: ==== l_s := ' INSERT INTO TEST1' INSERT INTO TEST2 Output: ==== 'INSERT INTO TEST' INSERT INTO TEST2 (2 Replies)
Discussion started by: saurabhbaisakhi
2 Replies

6. Shell Programming and Scripting

Delete line before pattern

Hi All, I want to delete partial line before the INSERT. Input: l_s := ' INSERT INTO TEST' Output: INSERT INTO TEST' (3 Replies)
Discussion started by: saurabhbaisakhi
3 Replies

7. UNIX for Dummies Questions & Answers

Find Pattern delete line and next line

I am trying to delete the line with pattern and the next line. Found the below command in forum which also deleted the previous line. how should i modify that to make sure that only the line with pattern and the next line are deleted but not the previous line? awk '/key... (1 Reply)
Discussion started by: rdhanek
1 Replies

8. Shell Programming and Scripting

find pattern, delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: FRM CHK 0000 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (4 Replies)
Discussion started by: nickg
4 Replies

9. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies

10. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies
Login or Register to Ask a Question