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 ?
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523
:7028:OUR
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 ?
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523
:7028:OUR
Please Use codetag and show us your expected output
cat file
some data
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523
:7028:OUR
some more data
awk '/^:[0-9]+:/ {f=0} /^:7023:/ {f=1} f' file
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523
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
some data
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
:7028:OUR
some more data
Your requirements are ambiguous and the output that you say should be produced does not match the sample input you provided. You say that:
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:
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.
@sandipgawale
You want the tag printed or not.
My output was:
: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?
Hi,
Try this (already see in another post ):
sed -n '/^:[0-9]*:/{$!N;$!N;$!N;p;}' file
Regards.
Try:
sed -n '/:7023:/,/:/p' file
I guess the requestor wants the 5th + lines suppressed when :7023: is encountered, until the next :
; anything else should print:
awk 'NR==1 || /^:/ {L=1E99} /^:7023:/ {L=NR+4} NR<L' file
some data
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
:7028:OUR
some more data
Input file is like
:7011:/20106407235
NATURE CONSTRUCTION
NEW DP ROAD
OPP GOVT SCHOOL
45500332
:7021:SAMPLE DATA ONE
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523
:7028:OUR
OUTPUT I NEED IS
:7011:/20106407235
NATURE CONSTRUCTION
NEW DP ROAD
OPP GOVT SCHOOL
45500332
:7021:SAMPLE DATA ONE
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
:7028:OUR
So i want line AC 20101906523 to be deleted or any more line after that if present till next : get deleted.
Try
$ cat <<eof | awk '!/^AC/'
:7011:/20106407235
NATURE CONSTRUCTION
NEW DP ROAD
OPP GOVT SCHOOL
45500332
:7021:SAMPLE DATA ONE
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
AC 20101906523
:7028:OUR
eof
:7011:/20106407235
NATURE CONSTRUCTION
NEW DP ROAD
OPP GOVT SCHOOL
45500332
:7021:SAMPLE DATA ONE
:7023:TEST LINE NUMBER
1101010021442 TESTING
HI HERE
PLEASE HELP ME OUT
:7028:OUR
for file use like this
$ awk '!/^AC/' file
OR
$ sed '/^AC/d' file
OR
$ perl -ni -e 'print unless /^AC/' file
Try:
awk '/^AC/{p=0} /^:/{p=1}p' file
Thanks RudiC .....