Delete a specific line containing non consecutive number?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete a specific line containing non consecutive number?
# 1  
Old 03-25-2014
Delete a specific line containing non consecutive number?

Dear Specialists,
I have following data

Code:
1 1 2 
2 2 3
3 3 6
4 3 4
5 4 9
6 5 11
7 6 7

and I would like to obtain data like below

Code:
1 1 2
2 2 3
4 3 4
7 6 7

which means that I want to leave lines containing a consecutive number at column 2 and 3 in same line.

I would really appreciate it a lot if anyone gives me a solution.

Thanks in advance.
# 2  
Old 03-25-2014
Try:
Code:
awk '($2+1)==$3' file

This User Gave Thanks to Subbeh For This Post:
# 3  
Old 03-25-2014
Subbeh,

Thanks a lot !!!! This really works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

Cut from specific line number to a line number

Hi All, I've a file like this.. Sheet1 a,1 a,2 a,3 a,4 a,5 Sheet2 a,6 a,7 a,8 a,9 a,10 Sheet3 a,11 a,12 a,13 (7 Replies)
Discussion started by: manab86
7 Replies

4. Shell Programming and Scripting

Delete specific line in awk

Hi, I'm totally new to awk, so thanks in advance for your help. I want to make a csv file out of a text file I've exported from a database I want to do two things: 1. Change pipes ("|") to commas (",") to make a text file into CSV 2. Remove the second line of the file, which is useless junk. ... (3 Replies)
Discussion started by: pip56789
3 Replies

5. Shell Programming and Scripting

Merge two non-consecutive lines based on line number or string

This is a variation of an earlier post found here: unixcom/shell-programming-scripting/159821-merge-two-non-consecutive-lines.html User Bartus11 was kind enough to solve that example. Previously, I needed help combining two lines that are non-consecutive in a file. Now I need to do the... (7 Replies)
Discussion started by: munkee
7 Replies

6. Shell Programming and Scripting

Delete all lines that start with a bigger number of a specific one.

E.g. the file is like this: I want to delete all lines that begin with a number larger than 2, ignoring the lines that doesn't begin with a number! PS:'2' is actually a variable that can have a lot of values:b:i bet you got it (10 Replies)
Discussion started by: hakermania
10 Replies

7. Shell Programming and Scripting

Find specific line and delete line after.

I'm looking for a way to search a file, in this case init.rc for a specific match, service adbd /sbin/adbd, and delete the a specific line after it Original: # adbd is controlled by the persist.service.adb.enable system property service adbd /sbin/adbd disabled After deletion: #... (5 Replies)
Discussion started by: GabrialDestruir
5 Replies

8. Shell Programming and Scripting

How would i delete a line at specific line number

Hi guys , I m writing a script to delete a line at particular location. But i m unable to use variable for specifying line number. for example. sed -n '7!p' filename works fine and deletes 7th line from my file but sed -n '$variable!p' filename gives following error. sed: -e... (12 Replies)
Discussion started by: pinga123
12 Replies

9. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

10. Shell Programming and Scripting

Adding a columnfrom a specifit line number to a specific line number

Hi, I have a huge file & I want to add a specific text in column. But I want to add this text from a specific line number to a specific line number & another text in to another range of line numbers. To be more specific: lets say my file has 1000 lines & 4 Columns. I want to add text "Hello"... (2 Replies)
Discussion started by: Ezy
2 Replies
Login or Register to Ask a Question