Need an awk command to delete a line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need an awk command to delete a line
# 1  
Old 02-18-2013
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
# 2  
Old 02-18-2013
Yes, you just print the lines or line parts you like!
# 3  
Old 02-19-2013
Hi ..Yes,am able 2 copy that error line to a separate file. My requirement is like I want that error line alone to be deleted from the main file so that I can process the main file for my purpose again ..
Please help me out ..
# 4  
Old 02-19-2013
It's a matter of identity perception. It is much harder to modify a file in place than to make a new file, and disk is cheap, so make a new file with only the lines you want and process that.
# 5  
Old 02-20-2013
HI .. I tried to do that and ended up in an error ..
awk -F"|" '{if (NF != 37) print $0 }' ${INPUTFILE} > ${ERRORFILE}

This is how i copy the line with extra delimiter to an error file , can u pls tell me how I can delete that particular line from my input file..
# 6  
Old 02-20-2013
NF equal 37 ? Not being an awk guy, not sure if it's == or =! Try it and see! OK:
Code:
awk -F"|" '{if (NF == 37) print $0 }' ${INPUTFILE} > ${NEWFILE}

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

2. UNIX for Dummies Questions & Answers

Using awk to delete a certain line

Ok I have a file that contains #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 $ main.sh name place 5 how would i go about deleteing the... (13 Replies)
Discussion started by: austing5
13 Replies

3. Shell Programming and Scripting

sed command to delete everything after > on line

I have a large data file that I need to edit. There are lines like, > <IDNUMBER> (ST000002) > <SUPPLIER> (ST000002) > <IDNUMBER> (ST000004) > <SUPPLIER> (ST000004) and I need to delete everything after the >, excepting the end of line. > <IDNUMBER> > <SUPPLIER> > <IDNUMBER> > ... (4 Replies)
Discussion started by: LMHmedchem
4 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

sed command to delete line

HI, Im using the below commmand to delete lines having "(" at the start of a line. sed -e '/^(/d' But i need a command to delete lines that has only "(" in it and no other strings. infile - asdf asdf ( asdf ( asd outfile (1 Reply)
Discussion started by: dvah
1 Replies

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

7. Shell Programming and Scripting

SED delete only first line command - Help need

Can any one help me how the sed delete only first line command (D) works. sed -f sedcmds File.txt In this how the sed delete only first line command (D) works to delete the blank lines appearing more than ones leaving only one blank and deleting others blanks. While doing step by step when... (2 Replies)
Discussion started by: gwgreen1
2 Replies

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

9. UNIX for Dummies Questions & Answers

delete contents from command line

How might I delete the contents of a file from the command line? (not delete the file) (4 Replies)
Discussion started by: juanbro
4 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