Help with a deleting lines based on a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with a deleting lines based on a pattern
# 1  
Old 10-21-2013
Question Help with a deleting lines based on a pattern

I have a header-detail file that goes like this:

Code:
SHP00288820131021110921
ORDER0156605920131021110921INMMMMFN
DETAIL0004 4C2Z      10769 AAFC 0000009600000094 4C2Z      10769 AAFC       0000672107 OIL
DETAIL0002 ER3Z      14300 E    0000001300000012 ER3Z      14300 E          0000672107 OIL
DETAIL0003 MBXT         58 R    0000004600000045 MBXT         58 R          0000672107 OIL
ORDER0156605820131021110921NIMMMMFN
DETAIL0001 4C4Z      10753 GA   0000007800000078 4C4Z      10753 GA         0000672108 OIL

The objective is to delete from the file ORDER number 01566058 a it's detail DETAIL0001 because order's layout is wrong and I do not want to keep it.

I've been googling but run out of ideas. Any help would be appreciated.
# 2  
Old 10-21-2013
Some more complete input data, and the output you'd want from it, would be helpful. This is a bit ambiguous as is.
# 3  
Old 10-21-2013
Try:
Code:
awk '/ORDER01566058/{getline;next}1' file

# 4  
Old 10-22-2013
Question

Quote:
Originally Posted by bartus11
Try:
Code:
awk '/ORDER01566058/{getline;next}1' file

That's exactly what i was looking for. Thanks bartus11. Talking about number 1 it could be variable, example.

Code:
ORDER0163069420130712102624BOAF52M000031473004790
DETAIL0003    9L1Z 7861202AC    0000000100000001    9L1Z 7861202AC          0000669478
ORDER0164796720130711114537INCWB6A
DETAIL0002   MAB39   16451JC    0000000100000001   MAB39   16451JC          00006692200012444329
DETAIL0001   MAB39   16450JC    0000000100000001   MAB39   16450JC          00006692200012444330
ORDER0165218120130711175459INCWB6A
DETAIL0004         1215876      0000000300000003         1215876            00006695690012445135
DETAIL0005   MAB39  12B637AG    0000031500000099   MAB39  12B637AG          00006692710012443789
DETAIL0015   MCE83 5464811BB    0000001000000001   MBE8Z 5464811B           00006692710012443785
DETAIL0001   M95SY15010974AB    0000000100000001   M95SY15010974AB          00006697540012447141
DETAIL0002   M95SY15010974AB    0000000100000001   M95SY15010974AB          00006697890012445414
ORDER0165647120130712120945BOAF52M000039493001759
DETAIL0002    AT4Z    6333A     0000000400000002    AT4Z    6333A           0000669461
DETAIL0001   M6L55   6B032AA    0000000200000002   M6L55   6B032AA          00006692960012444260
ORDER0166048820130712114708BOCWB6A
DETAIL0001   M8L55   5K214EC    0000000100000001   M8L55   5K214EC          00006694640012445152
ORDER0166074720130712102954BOAF52M000031473011149
DETAIL0001    DB5Z   9A407A     0000000100000001    DB5Z   9A407A           0000669459

As referred before orders could have N details and i have to determine how many lines should be deleted with the command. Is there's a way to index the file. I mean:

Code:
ORDER01630694 has DETAIL0003. (1)
ORDER01647967 has DETAIL0001 and DETAIL0002. (2)
ORDER01652181 has DETAIL0004, DETAIL0005, DETAIL0005, DETAIL0005 and DETAIL0002. (5)

and so on.

In that way could be easier to know the number lines that should be omitted.

Code:
awk '/ORDER01566058/{getline;next}N' file

Thanks in advanced.

Last edited by Scrutinizer; 10-22-2013 at 11:18 AM.. Reason: Additional code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting lines on matching certain pattern

hi I have a large xml file from which i have taken few lines . In this file I have to find for the string </invoices> and check if the 3 rd line after this string does not begin with <portCode> ,then i have to delete the string </invoices> and the next line having the string </shippingBill>... (13 Replies)
Discussion started by: sunnyboy
13 Replies

2. Shell Programming and Scripting

Vi editor deleting lines with specific pattern

Hi, I need to delete all lines in the file using vi editor which start with word aternqaco. Please assist. aternqaco.__oracle_base='/amdbqa01/app/oracle'#ORACLE_BASE set from environment aternqa.__oracle_base='/amdbqa01/app/oracle'#ORACLE_BASE set from environment... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

3. Shell Programming and Scripting

Deleting lines based on a condition for a group of files

hi i have a set of similar files. i want to delete lines until certain pattern appears in those files. for a single file the following command can be used but i want to do it for all the files at a time since the number is in thousands. awk '/PATTERN/{i++}i' file (6 Replies)
Discussion started by: anurupa777
6 Replies

4. Shell Programming and Scripting

Deleting lines from a stream after matching a pattern

Hi, I have a requirement to to an ldapsearch and remove the shadow attributes in the output file. What I do is ldapsearch() | operation to remove shadow > FILE The ldapsearch gives output like this(with same line formation): objectClass: FSConfig objectClass: extensibleObject fsCAIP:... (10 Replies)
Discussion started by: lorzinian
10 Replies

5. UNIX for Dummies Questions & Answers

[Solved] deleting pattern based lines in sed

HI, My input file contains below data: DFHDR 12345110 1,200 2,-100 1,100 2,123 12345110 1,300 2,200 DFTLR In the above data, the first line and last lines should be remove as well as the lines in which contains 110 as position(6,7,8 position) should also be removed, How we... (0 Replies)
Discussion started by: pandeesh
0 Replies

6. Shell Programming and Scripting

pattern matching over multiple lines and deleting the first

I've got a longish log file with content such as Uplink traffic: Downlink traffic: I want to parse the log file and remove any line that contains the string "Uplink traffic:" at the beginning of the line, but only if the line following it beginnings with the string "Downlink traffic:" (in... (7 Replies)
Discussion started by: Yorkie99
7 Replies

7. Shell Programming and Scripting

sed: deleting 5 lines after a specified pattern

As an example (just an example, this could apply to any block of text) say I have this: architecture x86_64 cputype CPU_TYPE_X86_64 cpusubtype CPU_SUBTYPE_X86_64_ALL offset 4096 size 2972420 align 2^12 (4096) architecture ppc64 cputype CPU_TYPE_POWERPC64 cpusubtype... (3 Replies)
Discussion started by: pcwiz
3 Replies

8. Shell Programming and Scripting

Delete lines between two patterns without deleting the second pattern

I want to delete lines like this sed '/FROM_HERE/,/TO_HERE/d' but I would like to *not* delete the second match, i.e. the TO_HERE line. How can I achieve this? Thank you! (1 Reply)
Discussion started by: Ilja
1 Replies

9. Shell Programming and Scripting

Finding duplicate lines and deleting folders based on them

Hi, I have research data, which is organized to 100 folders numbered 00-99. I have many sets of 100 folders, for different values of initial parameters. For some reason, the computer that ran the program to gather the data, didn't always create a unique seed for each folder. I anticipated that... (1 Reply)
Discussion started by: Jopi
1 Replies

10. Shell Programming and Scripting

deleting lines after pattern using sed

I have seen there are many sed posts but still it is quite difficult to apply other post to my own problem How can I delete all lines in a file from 2 lines after this pattern *End_fine_coreg:_NORMAL to the end of file? Cheers (2 Replies)
Discussion started by: larne
2 Replies
Login or Register to Ask a Question