Using awk to delete a certain line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using awk to delete a certain line
# 1  
Old 09-27-2012
Using awk to delete a certain line

Ok I have a file that contains

Code:
#num.txt
1 2 3
4 5 6
7 8 9

my script main.sh checks to see if the first two arguments exist in a seperate file and the third argument would be the value in the num.txt

so when i execute
Code:
$ main.sh name place 5

how would i go about deleteing the line with 5 in it so it would now display
Code:
1 2 3
7 8 9

thanks for looking!
# 2  
Old 09-27-2012
Hi


Code:
$ x=5
$ sed "/\b$x\b/d" file
1 2 3
7 8 9

Guru.
# 3  
Old 09-27-2012
Code:
awk '!/5/' file

# 4  
Old 09-27-2012
hey thanks for the reply, but another question.

What if it changes? im trying to use the 3rd argument to be the line i want to delete like this
Code:
awk "$3" num.txt

this wont work lol but this is what im trying to do if its possible.

Quote:
Originally Posted by guruprasadpr
Hi


Code:
$ x=5
$ sed "/\b$x\b/d" file
1 2 3
7 8 9

Guru.
# 5  
Old 09-27-2012
Code:
awk '!$0~x' x="$3" file

# 6  
Old 09-27-2012
Quote:
Originally Posted by tukuyomi
Code:
awk '!$0~x' x="$3" file

tried this; the file still contains all three lines any other ideas?
# 7  
Old 09-27-2012
try this..

For checking entire row.

Code:
awk  -v x="$3"  '$0 !~ x' file

For checking second column..
Code:
awk  -v x="$3"  '$2 != x' file


Last edited by pamu; 09-27-2012 at 02:52 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk find and delete line from list

good day i have a list of numbers in input.txt, i would like to compare to file.txt and delete the line that number appears in file.txt . input.txt: 4558980 5525628 3595233 2650083 2219411 3529741 4675897 3070869 0014685 6365902 file.txt: one-two-three-4558980.txt... (7 Replies)
Discussion started by: klein
7 Replies

2. Shell Programming and Scripting

If the value > 100 delete the line with awk or sed

if the value > 100 delete the line delay time: 42.978 ms delay time: 43.684 ms delay time: 41.082 ms delay time: 44.845 ms delay time: 40000.057 ms delay time: 41.158 ms delay time: 42.239 ms delay time: 50.579 ms delay time: 46.334 ms to (7 Replies)
Discussion started by: yanglei_fage
7 Replies

3. Shell Programming and Scripting

awk delete line if $5 contains string from list

(5 Replies)
Discussion started by: chrisjorg
5 Replies

4. UNIX for Dummies Questions & Answers

Need an awk command to delete a line

Hi all, As of now am using an awk command to check the number of columns in a file that has 10 lakh rows. Is it possible to remove that particular line having an extra column and copy the remaining lines to a new file ? YOUR HELP IS HIGHLY APPRECIATED. THANKS IN ADVANCE (5 Replies)
Discussion started by: Rahul619
5 Replies

5. UNIX for Dummies Questions & Answers

Awk match on columns and delete line

Hi, I have a file like this a 1 2 b 2 2 c 2 3 d 4 5 f 5 6 output a 1 2 c 2 3 d 4 5 f 5 6 Basically, I want to delete the whole line if $2 and $3 are the same. Thanks (5 Replies)
Discussion started by: jacobs.smith
5 Replies

6. 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

7. Shell Programming and Scripting

delete more than one line awk or perl

Hi all! How can a file be rid of three lines in sequence like the sample below: ... </s> <s> <w></w> </s> <s> ...to get: ... </s> <s> ... Note that the digits between square brackets may be more than one, comprising a comma, or a full-stop; and that the string between brackets... (1 Reply)
Discussion started by: mjomba
1 Replies

8. Shell Programming and Scripting

Delete line with sed or awk (with specified condition)

Hello. I'm trying to delete the lines of a file does not contain the letter "T " (for example) at position 26. So far, I could only print the result: awk '{if (substr ($ 1,1,26)! ~ / T /) print}' file.txt How I can do to eliminate the lines that meet this condition? Help please. ... (4 Replies)
Discussion started by: </kida>
4 Replies

9. Shell Programming and Scripting

how to delete line with awk

Hi I have a multi -line file which is sorted by the 1-st colomn in the following format: 400 0000 0001 1000 1010 0111 0000 1000 0000 402 1101 0000 1100 1010 0111 1000 1000 0000 403 1001 0000 1100 1010 0111 0000 1000 0000 495 1000 0000 1100 1010 0111 0000 1000 0000 500 0000 0001 1000 0010... (2 Replies)
Discussion started by: aoussenko
2 Replies

10. Shell Programming and Scripting

awk : delete ^M at the end of the line

Hi all, I'm newbi in scripting. could someone tell how to delete the ^M at the end of the linie with an awk command. many thanks in advance. (2 Replies)
Discussion started by: liliput
2 Replies
Login or Register to Ask a Question