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?
# 8  
Old 10-01-2008
Possibly there is are spaces at the beginning

Try this sample.
Code:
sed 's/^  *//g' b | grep -v "^[6-9] "

( certainly, not an efficient way of doing it )
# 9  
Old 10-01-2008
Thanks for the input PWSwebmaster however that grep-v you adjusted still didn't work. The closest I can get is doing the following but it's still doesn't delete all the lines I want.

backups01laxint.liuc(s){jsandova}[~]<0>$ nsrjb -v | awk -F' ' '$3>=01{print $0}' | cut -b 1-79 | grep -v "("
setting verbosity level to `1'
slot volume used pool barcode
1: intwindows.0005 9% intwindows 010159L2
2: intunix.0009 19% intunix 010155L2
4: intrman.0002 2% intrman 010395L2
*not registered in the NetWorker media data base
# 10  
Old 10-01-2008
Quote:
foreach $l (@lines) {
if ($l !~ /^6/ && $l !~ /^7/ && $l !~ /^8/ && $l !~ /^9/) {
print FILE $l;
}
}
Making slight modifications

Code:
$l =~ s/^  *//g;
if (!( $l >= 6 && $l <= 9 )) {
  print FILE $l;
}

# 11  
Old 10-01-2008
Quote:
Originally Posted by jsandova
Thanks for the input PWSwebmaster however that grep-v you adjusted still didn't work. The closest I can get is doing the following but it's still doesn't delete all the lines I want.

backups01laxint.liuc(s){jsandova}[~]<0>$ nsrjb -v | awk -F' ' '$3>=01{print $0}' | cut -b 1-79 | grep -v "("
setting verbosity level to `1'
slot volume used pool barcode
1: intwindows.0005 9% intwindows 010159L2
2: intunix.0009 19% intunix 010155L2
4: intrman.0002 2% intrman 010395L2
*not registered in the NetWorker media data base

Try escaping the round brackets.

Code:
grep -v "^\(\s|\t\)*[6-9] " file

# 12  
Old 10-01-2008
Quote:
Originally Posted by matrixmadhan
Making slight modifications

Code:
$l =~ s/^  *//g;
if (!( $l >= 6 && $l <= 9 )) {
  print FILE $l;
}

That'll work too, but don't need the global option since anchored matches can only match once. Smilie
# 13  
Old 10-01-2008
Code:
 # grep  -v "^ *[6-9]" file
backups01laxint.liuc(s){jsandova}[~]<0>$ nsrjb -v |  awk -F' ' '$3>=01{print $0}'  | cut -b 1-79 | cat -n | grep -v "^[6-9] "
setting verbosity level to `1'
     1    slot  volume                                     used  pool        barcode
     2       1: intwindows.0005                              9%  intwindows  010159L2
     3       2: intunix.0009                                19%  intunix     010155L2
     4       4: intrman.0002                                 2%  intrman     010395L2
     5      24: Cleaning Tape (50 uses left) 000002L1

# 14  
Old 10-02-2008
Quote:
Originally Posted by PWSwebmaster
That'll work too, but don't need the global option since anchored matches can only match once. Smilie
You are right !

Code:
$l =~ s/^  *//;
print FILE $1 if (!( $l >= 6 && $l <= 9 ));

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