How to delete a row in a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delete a row in a file?
# 15  
Old 10-02-2008
What about this solution in general:
Code:
..... | sed 6,9d 
..... | awk 'NR~"[6-9]"{next}1'

or for the OP request in special:
Code:
.... | sed 5q
.... | awk 'NR==6{exit}1'

... and don't make your life complicated Smilie

Last edited by danmero; 10-02-2008 at 11:12 AM..
# 16  
Old 10-02-2008
danmero,
That is exactly what I was look for. Simple and short, I however have not used sed much so was not sure on how to implement it. Thanks for the great tip!

backups01laxint.liuc(s){jsandova}[~]<0>$ nsrjb -v | awk -F' ' '$3>=01{print $0}' | cut -b 1-79 | sed 5q
setting verbosity level to `1'
slot volume used pool barcode
1: intwindows.0005 9% intwindows 010159L2
2: intunix.0009 20% intunix 010155L2
4: intrman.0002 2% intrman 010395L2
24: Cleaning Tape (50 uses left) 000002L1 000002L1
# 17  
Old 10-03-2008
Quote:
Originally Posted by danmero
What about this solution in general:
Code:
[...]
..... | awk 'NR~"[6-9]"{next}1'

or for the OP request in special:
[code]
[...]
Quote:
Yes,
or even:

Code:
awk '!(NR~"[6-9]")'

Oops,
it should be:

Code:
awk '!(NR~/^[6-9]$/)'

or:

Code:
awk 'NR~/^[6-9]$/{next}1'


Last edited by radoulov; 10-03-2008 at 08:32 AM.. Reason: wrong code
# 18  
Old 10-03-2008
Quote:
Originally Posted by radoulov
Code:
awk '!(NR~/^[6-9]$/)'

I like this one Smilie

Last edited by danmero; 10-03-2008 at 06:07 PM.. Reason: close quote
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. UNIX for Dummies Questions & Answers

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. (8 Replies)
Discussion started by: natraj005
8 Replies

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

10. 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
Login or Register to Ask a Question