Filter out lines that have a column of text begining at a particular column number [closed]

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a text file containing columnar data and I would like to filter out lines that meet a specific criteria: the data in the second-to-last column begins at column 161 rather than 162. So given this:
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access MF20170901150328000NGS2 20170901150328000
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access PF20170901150328000NGS2 20170901150328000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
I'm left with this after processing:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
How can I achieve this with command line tools?
UPDATE
I want to delete the lines with the matched pattern and also need to delete the last columns in the file. So my ultimate output should be like below.
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query
text-processing
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, G-Man, SatÃ
 Katsura, Anthony Geoghegan Nov 7 '17 at 14:23
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
 |Â
show 4 more comments
up vote
0
down vote
favorite
I have a text file containing columnar data and I would like to filter out lines that meet a specific criteria: the data in the second-to-last column begins at column 161 rather than 162. So given this:
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access MF20170901150328000NGS2 20170901150328000
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access PF20170901150328000NGS2 20170901150328000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
I'm left with this after processing:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
How can I achieve this with command line tools?
UPDATE
I want to delete the lines with the matched pattern and also need to delete the last columns in the file. So my ultimate output should be like below.
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query
text-processing
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, G-Man, SatÃ
 Katsura, Anthony Geoghegan Nov 7 '17 at 14:23
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Are the lines wrapped like that, such that groups of them should go together?
â Jeff Schaller
Nov 6 '17 at 16:16
1
In your example there is no line longer than 84 characters, and all lines have trailing spaces. Please post a real example.
â AlexP
Nov 6 '17 at 17:19
1
It's not very clear what you're asking. What is the criteria for lines to be deleted?
â Time4Tea
Nov 6 '17 at 20:57
@ñÃÂsýù÷ I have posted some input data from the file in the question. IF you look at the last 2 columns in the data "MF20170901150328000NGS2"(161-184) and "B20171016171130000NGS2"(162-184). I need to delete the whole row from the file if i find any column with positions (161-184). In the above input which i mentioned in the question the first 2 lines needs to get deleted.Layer provided a solution to this. I need to include one more logic in which it should delete the last 2 columns from the entire file also. So finally i need to delete the complete line if it matches (161-184) position..contd
â Ravi Rock
Nov 8 '17 at 11:56
and also it needs to delete the last 2 columns from the entire file i.e (B20171016171130000NGS2 20171016171130000). Please let me know whether my requirement is clear or not. In my updated question i have provided the final ouput.
â Ravi Rock
Nov 8 '17 at 11:57
 |Â
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a text file containing columnar data and I would like to filter out lines that meet a specific criteria: the data in the second-to-last column begins at column 161 rather than 162. So given this:
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access MF20170901150328000NGS2 20170901150328000
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access PF20170901150328000NGS2 20170901150328000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
I'm left with this after processing:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
How can I achieve this with command line tools?
UPDATE
I want to delete the lines with the matched pattern and also need to delete the last columns in the file. So my ultimate output should be like below.
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query
text-processing
I have a text file containing columnar data and I would like to filter out lines that meet a specific criteria: the data in the second-to-last column begins at column 161 rather than 162. So given this:
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access MF20170901150328000NGS2 20170901150328000
EP10101 12011 SC0 NCI Application Security DLS3270 SC040P20Maintain User Access PF20170901150328000NGS2 20170901150328000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
I'm left with this after processing:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
How can I achieve this with command line tools?
UPDATE
I want to delete the lines with the matched pattern and also need to delete the last columns in the file. So my ultimate output should be like below.
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query
text-processing
edited Nov 8 '17 at 10:52
ñÃÂsýù÷
15.5k92563
15.5k92563
asked Nov 6 '17 at 16:09
Ravi Rock
135
135
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, G-Man, SatÃ
 Katsura, Anthony Geoghegan Nov 7 '17 at 14:23
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, G-Man, SatÃ
 Katsura, Anthony Geoghegan Nov 7 '17 at 14:23
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Are the lines wrapped like that, such that groups of them should go together?
â Jeff Schaller
Nov 6 '17 at 16:16
1
In your example there is no line longer than 84 characters, and all lines have trailing spaces. Please post a real example.
â AlexP
Nov 6 '17 at 17:19
1
It's not very clear what you're asking. What is the criteria for lines to be deleted?
â Time4Tea
Nov 6 '17 at 20:57
@ñÃÂsýù÷ I have posted some input data from the file in the question. IF you look at the last 2 columns in the data "MF20170901150328000NGS2"(161-184) and "B20171016171130000NGS2"(162-184). I need to delete the whole row from the file if i find any column with positions (161-184). In the above input which i mentioned in the question the first 2 lines needs to get deleted.Layer provided a solution to this. I need to include one more logic in which it should delete the last 2 columns from the entire file also. So finally i need to delete the complete line if it matches (161-184) position..contd
â Ravi Rock
Nov 8 '17 at 11:56
and also it needs to delete the last 2 columns from the entire file i.e (B20171016171130000NGS2 20171016171130000). Please let me know whether my requirement is clear or not. In my updated question i have provided the final ouput.
â Ravi Rock
Nov 8 '17 at 11:57
 |Â
show 4 more comments
1
Are the lines wrapped like that, such that groups of them should go together?
â Jeff Schaller
Nov 6 '17 at 16:16
1
In your example there is no line longer than 84 characters, and all lines have trailing spaces. Please post a real example.
â AlexP
Nov 6 '17 at 17:19
1
It's not very clear what you're asking. What is the criteria for lines to be deleted?
â Time4Tea
Nov 6 '17 at 20:57
@ñÃÂsýù÷ I have posted some input data from the file in the question. IF you look at the last 2 columns in the data "MF20170901150328000NGS2"(161-184) and "B20171016171130000NGS2"(162-184). I need to delete the whole row from the file if i find any column with positions (161-184). In the above input which i mentioned in the question the first 2 lines needs to get deleted.Layer provided a solution to this. I need to include one more logic in which it should delete the last 2 columns from the entire file also. So finally i need to delete the complete line if it matches (161-184) position..contd
â Ravi Rock
Nov 8 '17 at 11:56
and also it needs to delete the last 2 columns from the entire file i.e (B20171016171130000NGS2 20171016171130000). Please let me know whether my requirement is clear or not. In my updated question i have provided the final ouput.
â Ravi Rock
Nov 8 '17 at 11:57
1
1
Are the lines wrapped like that, such that groups of them should go together?
â Jeff Schaller
Nov 6 '17 at 16:16
Are the lines wrapped like that, such that groups of them should go together?
â Jeff Schaller
Nov 6 '17 at 16:16
1
1
In your example there is no line longer than 84 characters, and all lines have trailing spaces. Please post a real example.
â AlexP
Nov 6 '17 at 17:19
In your example there is no line longer than 84 characters, and all lines have trailing spaces. Please post a real example.
â AlexP
Nov 6 '17 at 17:19
1
1
It's not very clear what you're asking. What is the criteria for lines to be deleted?
â Time4Tea
Nov 6 '17 at 20:57
It's not very clear what you're asking. What is the criteria for lines to be deleted?
â Time4Tea
Nov 6 '17 at 20:57
@ñÃÂsýù÷ I have posted some input data from the file in the question. IF you look at the last 2 columns in the data "MF20170901150328000NGS2"(161-184) and "B20171016171130000NGS2"(162-184). I need to delete the whole row from the file if i find any column with positions (161-184). In the above input which i mentioned in the question the first 2 lines needs to get deleted.Layer provided a solution to this. I need to include one more logic in which it should delete the last 2 columns from the entire file also. So finally i need to delete the complete line if it matches (161-184) position..contd
â Ravi Rock
Nov 8 '17 at 11:56
@ñÃÂsýù÷ I have posted some input data from the file in the question. IF you look at the last 2 columns in the data "MF20170901150328000NGS2"(161-184) and "B20171016171130000NGS2"(162-184). I need to delete the whole row from the file if i find any column with positions (161-184). In the above input which i mentioned in the question the first 2 lines needs to get deleted.Layer provided a solution to this. I need to include one more logic in which it should delete the last 2 columns from the entire file also. So finally i need to delete the complete line if it matches (161-184) position..contd
â Ravi Rock
Nov 8 '17 at 11:56
and also it needs to delete the last 2 columns from the entire file i.e (B20171016171130000NGS2 20171016171130000). Please let me know whether my requirement is clear or not. In my updated question i have provided the final ouput.
â Ravi Rock
Nov 8 '17 at 11:57
and also it needs to delete the last 2 columns from the entire file i.e (B20171016171130000NGS2 20171016171130000). Please let me know whether my requirement is clear or not. In my updated question i have provided the final ouput.
â Ravi Rock
Nov 8 '17 at 11:57
 |Â
show 4 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Bit of a guess since the question is not entirely clear but
sed '/^.160S+/d' file
If this finds "data" (non-whitespace) at column 161 the line is deleted. All other lines are printed. This results in the output:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
(Can't help but think there is a better approach but this is all OP provides.)
Hi Layer. Is it possible to delete the last 2 columns if the same criteria matches?
â Ravi Rock
Nov 7 '17 at 15:30
You want something like this?sed 's/^(.160S.*)..$/1/g' file
â B Layer
Nov 7 '17 at 16:01
Actually, maybe what you mean is to delete the entire column blocks rather than one-character wide columns like those we have been talking about. If so try this:sed 's/^(.160)S+.*/1/' file
â B Layer
Nov 7 '17 at 23:06
Thanks Layer. I got the correct scenario now. After successfully deleting the lines with the match i also need to delete the last columns in the file. So my ultimate output should be like I have edited the question.
â Ravi Rock
Nov 8 '17 at 8:45
@Layer Can you help on this one?
â Ravi Rock
Nov 8 '17 at 15:01
 |Â
show 1 more comment
up vote
-1
down vote
Use below command as tested it worked fine
for i in $(awk 'if ((length($1) > "160") && (length($1) < "184"))print NR' filename); do sed "$i"d p.txt; done
Why usesedif youâÂÂre already usingawk?
â Stephen Kitt
Nov 7 '17 at 21:44
@StephenKitt Its Just an alternative As we can achieve using both sed and awk
â Praveen Kumar BS
Nov 8 '17 at 6:55
My point is that you can do the whole operation in AWK, no need to usesedin a loop afterwards.
â Stephen Kitt
Nov 8 '17 at 7:04
@StephenKitt Yes agree
â Praveen Kumar BS
Nov 8 '17 at 7:09
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Bit of a guess since the question is not entirely clear but
sed '/^.160S+/d' file
If this finds "data" (non-whitespace) at column 161 the line is deleted. All other lines are printed. This results in the output:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
(Can't help but think there is a better approach but this is all OP provides.)
Hi Layer. Is it possible to delete the last 2 columns if the same criteria matches?
â Ravi Rock
Nov 7 '17 at 15:30
You want something like this?sed 's/^(.160S.*)..$/1/g' file
â B Layer
Nov 7 '17 at 16:01
Actually, maybe what you mean is to delete the entire column blocks rather than one-character wide columns like those we have been talking about. If so try this:sed 's/^(.160)S+.*/1/' file
â B Layer
Nov 7 '17 at 23:06
Thanks Layer. I got the correct scenario now. After successfully deleting the lines with the match i also need to delete the last columns in the file. So my ultimate output should be like I have edited the question.
â Ravi Rock
Nov 8 '17 at 8:45
@Layer Can you help on this one?
â Ravi Rock
Nov 8 '17 at 15:01
 |Â
show 1 more comment
up vote
1
down vote
accepted
Bit of a guess since the question is not entirely clear but
sed '/^.160S+/d' file
If this finds "data" (non-whitespace) at column 161 the line is deleted. All other lines are printed. This results in the output:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
(Can't help but think there is a better approach but this is all OP provides.)
Hi Layer. Is it possible to delete the last 2 columns if the same criteria matches?
â Ravi Rock
Nov 7 '17 at 15:30
You want something like this?sed 's/^(.160S.*)..$/1/g' file
â B Layer
Nov 7 '17 at 16:01
Actually, maybe what you mean is to delete the entire column blocks rather than one-character wide columns like those we have been talking about. If so try this:sed 's/^(.160)S+.*/1/' file
â B Layer
Nov 7 '17 at 23:06
Thanks Layer. I got the correct scenario now. After successfully deleting the lines with the match i also need to delete the last columns in the file. So my ultimate output should be like I have edited the question.
â Ravi Rock
Nov 8 '17 at 8:45
@Layer Can you help on this one?
â Ravi Rock
Nov 8 '17 at 15:01
 |Â
show 1 more comment
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Bit of a guess since the question is not entirely clear but
sed '/^.160S+/d' file
If this finds "data" (non-whitespace) at column 161 the line is deleted. All other lines are printed. This results in the output:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
(Can't help but think there is a better approach but this is all OP provides.)
Bit of a guess since the question is not entirely clear but
sed '/^.160S+/d' file
If this finds "data" (non-whitespace) at column 161 the line is deleted. All other lines are printed. This results in the output:
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016171130000NGS2 20171016171130000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS07P10NCFI Lease/Loan Payout Query B20171016134250000NGS2 20171016134250000
OS10101 12011 DLS NCI Dealer Systems DLS3270 DLS20P10RDR Maintenance B20171016143354000NGS2 20171016143354000
(Can't help but think there is a better approach but this is all OP provides.)
edited Nov 7 '17 at 6:55
answered Nov 7 '17 at 2:48
B Layer
3,9241525
3,9241525
Hi Layer. Is it possible to delete the last 2 columns if the same criteria matches?
â Ravi Rock
Nov 7 '17 at 15:30
You want something like this?sed 's/^(.160S.*)..$/1/g' file
â B Layer
Nov 7 '17 at 16:01
Actually, maybe what you mean is to delete the entire column blocks rather than one-character wide columns like those we have been talking about. If so try this:sed 's/^(.160)S+.*/1/' file
â B Layer
Nov 7 '17 at 23:06
Thanks Layer. I got the correct scenario now. After successfully deleting the lines with the match i also need to delete the last columns in the file. So my ultimate output should be like I have edited the question.
â Ravi Rock
Nov 8 '17 at 8:45
@Layer Can you help on this one?
â Ravi Rock
Nov 8 '17 at 15:01
 |Â
show 1 more comment
Hi Layer. Is it possible to delete the last 2 columns if the same criteria matches?
â Ravi Rock
Nov 7 '17 at 15:30
You want something like this?sed 's/^(.160S.*)..$/1/g' file
â B Layer
Nov 7 '17 at 16:01
Actually, maybe what you mean is to delete the entire column blocks rather than one-character wide columns like those we have been talking about. If so try this:sed 's/^(.160)S+.*/1/' file
â B Layer
Nov 7 '17 at 23:06
Thanks Layer. I got the correct scenario now. After successfully deleting the lines with the match i also need to delete the last columns in the file. So my ultimate output should be like I have edited the question.
â Ravi Rock
Nov 8 '17 at 8:45
@Layer Can you help on this one?
â Ravi Rock
Nov 8 '17 at 15:01
Hi Layer. Is it possible to delete the last 2 columns if the same criteria matches?
â Ravi Rock
Nov 7 '17 at 15:30
Hi Layer. Is it possible to delete the last 2 columns if the same criteria matches?
â Ravi Rock
Nov 7 '17 at 15:30
You want something like this?
sed 's/^(.160S.*)..$/1/g' fileâ B Layer
Nov 7 '17 at 16:01
You want something like this?
sed 's/^(.160S.*)..$/1/g' fileâ B Layer
Nov 7 '17 at 16:01
Actually, maybe what you mean is to delete the entire column blocks rather than one-character wide columns like those we have been talking about. If so try this:
sed 's/^(.160)S+.*/1/' fileâ B Layer
Nov 7 '17 at 23:06
Actually, maybe what you mean is to delete the entire column blocks rather than one-character wide columns like those we have been talking about. If so try this:
sed 's/^(.160)S+.*/1/' fileâ B Layer
Nov 7 '17 at 23:06
Thanks Layer. I got the correct scenario now. After successfully deleting the lines with the match i also need to delete the last columns in the file. So my ultimate output should be like I have edited the question.
â Ravi Rock
Nov 8 '17 at 8:45
Thanks Layer. I got the correct scenario now. After successfully deleting the lines with the match i also need to delete the last columns in the file. So my ultimate output should be like I have edited the question.
â Ravi Rock
Nov 8 '17 at 8:45
@Layer Can you help on this one?
â Ravi Rock
Nov 8 '17 at 15:01
@Layer Can you help on this one?
â Ravi Rock
Nov 8 '17 at 15:01
 |Â
show 1 more comment
up vote
-1
down vote
Use below command as tested it worked fine
for i in $(awk 'if ((length($1) > "160") && (length($1) < "184"))print NR' filename); do sed "$i"d p.txt; done
Why usesedif youâÂÂre already usingawk?
â Stephen Kitt
Nov 7 '17 at 21:44
@StephenKitt Its Just an alternative As we can achieve using both sed and awk
â Praveen Kumar BS
Nov 8 '17 at 6:55
My point is that you can do the whole operation in AWK, no need to usesedin a loop afterwards.
â Stephen Kitt
Nov 8 '17 at 7:04
@StephenKitt Yes agree
â Praveen Kumar BS
Nov 8 '17 at 7:09
add a comment |Â
up vote
-1
down vote
Use below command as tested it worked fine
for i in $(awk 'if ((length($1) > "160") && (length($1) < "184"))print NR' filename); do sed "$i"d p.txt; done
Why usesedif youâÂÂre already usingawk?
â Stephen Kitt
Nov 7 '17 at 21:44
@StephenKitt Its Just an alternative As we can achieve using both sed and awk
â Praveen Kumar BS
Nov 8 '17 at 6:55
My point is that you can do the whole operation in AWK, no need to usesedin a loop afterwards.
â Stephen Kitt
Nov 8 '17 at 7:04
@StephenKitt Yes agree
â Praveen Kumar BS
Nov 8 '17 at 7:09
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
Use below command as tested it worked fine
for i in $(awk 'if ((length($1) > "160") && (length($1) < "184"))print NR' filename); do sed "$i"d p.txt; done
Use below command as tested it worked fine
for i in $(awk 'if ((length($1) > "160") && (length($1) < "184"))print NR' filename); do sed "$i"d p.txt; done
edited Nov 7 '17 at 21:44
Stephen Kitt
144k22312377
144k22312377
answered Nov 7 '17 at 7:42
Praveen Kumar BS
1,010128
1,010128
Why usesedif youâÂÂre already usingawk?
â Stephen Kitt
Nov 7 '17 at 21:44
@StephenKitt Its Just an alternative As we can achieve using both sed and awk
â Praveen Kumar BS
Nov 8 '17 at 6:55
My point is that you can do the whole operation in AWK, no need to usesedin a loop afterwards.
â Stephen Kitt
Nov 8 '17 at 7:04
@StephenKitt Yes agree
â Praveen Kumar BS
Nov 8 '17 at 7:09
add a comment |Â
Why usesedif youâÂÂre already usingawk?
â Stephen Kitt
Nov 7 '17 at 21:44
@StephenKitt Its Just an alternative As we can achieve using both sed and awk
â Praveen Kumar BS
Nov 8 '17 at 6:55
My point is that you can do the whole operation in AWK, no need to usesedin a loop afterwards.
â Stephen Kitt
Nov 8 '17 at 7:04
@StephenKitt Yes agree
â Praveen Kumar BS
Nov 8 '17 at 7:09
Why use
sed if youâÂÂre already using awk?â Stephen Kitt
Nov 7 '17 at 21:44
Why use
sed if youâÂÂre already using awk?â Stephen Kitt
Nov 7 '17 at 21:44
@StephenKitt Its Just an alternative As we can achieve using both sed and awk
â Praveen Kumar BS
Nov 8 '17 at 6:55
@StephenKitt Its Just an alternative As we can achieve using both sed and awk
â Praveen Kumar BS
Nov 8 '17 at 6:55
My point is that you can do the whole operation in AWK, no need to use
sed in a loop afterwards.â Stephen Kitt
Nov 8 '17 at 7:04
My point is that you can do the whole operation in AWK, no need to use
sed in a loop afterwards.â Stephen Kitt
Nov 8 '17 at 7:04
@StephenKitt Yes agree
â Praveen Kumar BS
Nov 8 '17 at 7:09
@StephenKitt Yes agree
â Praveen Kumar BS
Nov 8 '17 at 7:09
add a comment |Â
1
Are the lines wrapped like that, such that groups of them should go together?
â Jeff Schaller
Nov 6 '17 at 16:16
1
In your example there is no line longer than 84 characters, and all lines have trailing spaces. Please post a real example.
â AlexP
Nov 6 '17 at 17:19
1
It's not very clear what you're asking. What is the criteria for lines to be deleted?
â Time4Tea
Nov 6 '17 at 20:57
@ñÃÂsýù÷ I have posted some input data from the file in the question. IF you look at the last 2 columns in the data "MF20170901150328000NGS2"(161-184) and "B20171016171130000NGS2"(162-184). I need to delete the whole row from the file if i find any column with positions (161-184). In the above input which i mentioned in the question the first 2 lines needs to get deleted.Layer provided a solution to this. I need to include one more logic in which it should delete the last 2 columns from the entire file also. So finally i need to delete the complete line if it matches (161-184) position..contd
â Ravi Rock
Nov 8 '17 at 11:56
and also it needs to delete the last 2 columns from the entire file i.e (B20171016171130000NGS2 20171016171130000). Please let me know whether my requirement is clear or not. In my updated question i have provided the final ouput.
â Ravi Rock
Nov 8 '17 at 11:57