How to delete a row in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to delete a row in a file
# 1  
Old 07-05-2010
Question How to delete a row in a file

hi team,


i have a file txt1 , in that file there r 10 lines . my aim is to cut 2nd and 6th line of the file .


what command we can use for this scenario.
# 2  
Old 07-05-2010
Code:
awk 'NR==2 || NR==6 {next}1' txt1

# 3  
Old 07-05-2010
Quote:
Originally Posted by zaxxon
Code:
awk 'NR==2 || NR==6 {next}1' txt1


thanks zaxxon for ur answer , but its not working its shows the following error

awk: syntax error near line 1
awk: bailing out near line 1
# 4  
Old 07-05-2010
Code:
awk 'NR==2 || NR==6 {print}' txt1

should work.
# 5  
Old 07-05-2010
Quote:
Originally Posted by hergp
Code:
awk 'NR==2 || NR==6 {print}' txt1

should work.
yes hergp its working , but let me explain once again what i want

the content of the file txt1 is
HTML Code:
 
hi how are u
heloo boss how u doing
may i help u
i got the bike
today its too hot outside
hi boss
its too good to buy this car

and my excepted output is

HTML Code:
hi how are u
may i help u
i got the bike
today its too hot outside
its too good to buy this car
# 6  
Old 07-05-2010
Ahh, I misunderstood you. Try this:
Code:
nawk 'NR!=2 && NR!=6 {print}' txt1

# 7  
Old 07-05-2010
Quote:
Originally Posted by hergp
Ahh, I misunderstood you. Try this:
Code:
nawk 'NR!=2 && NR!=6 {print}' txt1


thnk u hergp , its working perfectly.
i have a doubt hergp
Code:
 
nawk 'NR!=2 && NR!=6 {print}' txt1

in the above command without {print} also working and same output , then y we are using tat one
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to delete row in csv file on date range?

I want to delete row in csv file , which row value from 2009-10-01 to 2011-06-03 using script.my csv row data look like: 2009-10-01 2011-03-30 2011-03-31 2011-04-01 2011-06-03 2011-06-30 2011-07-01 2011-09-28 ... (7 Replies)
Discussion started by: rakibul639
7 Replies

2. Shell Programming and Scripting

Delete duplicate row

Hi all, how can delete duplicate files in file form, e.g. $cat file1 aaa 123 234 345 456 bbb 345 345 657 568 ccc 345 768 897 456 aaa 123 234 345 456 ddd 786 784 234 263 ccc 345 768 897 456 aaa 123 234 345 456 ccc 345 768 897 456 then i need ouput file1 some, (4 Replies)
Discussion started by: aav1307
4 Replies

3. Shell Programming and Scripting

Search row by row from one file to another file if match is found print few colums of file 2

this is the requirement list.txt table1 table2 table3 testfile.txt name#place#data#select * from table1 name2#place2#data2#select * from table 10 innerjoin table3 name2#place2#data2#select * from table 10 output name place table1 name2 place table3 i tried using awk (7 Replies)
Discussion started by: vamsekumar
7 Replies

4. Shell Programming and Scripting

Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this. CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam tg93 77 T C T T T T T tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies

5. Shell Programming and Scripting

delete a row in csv file based on the date

Hi, I have a csv file with old data..i need to have only last 30 days from the current dateof data in the file.The fourth field in the file is a date field.i need to write a script to delete the old data by comparing the the fourth field with the (current date -30).I need to delete the rows in... (2 Replies)
Discussion started by: pals70423
2 Replies

6. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

7. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

8. Shell Programming and Scripting

How to Delete Last Row from .csv file in perl

Hi , I've a perl script to convert .xls to .csv .After conversion I want to delete first 28 and the last row from .csv file.Is there any efficent way to achive this both together. I'm deleting first 28 rows by using folllowing my perl code: exec " tail -n+28 infile.csv > outfile.csv ... (7 Replies)
Discussion started by: ajaypatil_am
7 Replies

9. UNIX for Dummies Questions & Answers

Delete first row of csv file

I have a csv file, which is > 2 Gigs. I need to BCP that file to Sybase db , but I cant upload that b'caz first row of the file is failing. ( having some errors probably.) I can manually insert the first line into db & then I can upload the rest of the data in file, if i can delete the first row. ... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

10. Shell Programming and Scripting

How to delete a row in a file?

Does anyone know a way to delete rows 6-9 from the below output? I have searched the forum but did not find any thing helpful. backups01laxint.liuc(s){jsandova}<0>$ nsrjb -v | awk -F' ' '$3>=01{print $0}' | cut -b 1-79 | cat -n setting verbosity level to `1' 1 slot volume ... (17 Replies)
Discussion started by: jsandova
17 Replies
Login or Register to Ask a Question