Deleting Lines from .csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting Lines from .csv file
# 1  
Old 11-13-2006
Deleting Lines from .csv file

Hello All,

I have a .csv file and I have to delete the selcted records stored in a vairable
e.g
echo $lname
7 88 91 94 97 100 103 106
I dont know how to pass the variable name to "sed" for deleting the $lname from a file
can any one help as this is very urgent.

$lname is changing the lines number so there is no fix line number stored in $lname this is upto the file.
009satya
# 2  
Old 11-13-2006
A possible solution using awk :
Code:
awk -v excl=" $lname " '! index(excl, " " NR " ")' csv_file


Jean-Pierre.
# 3  
Old 11-13-2006
Hello Jean,

Thanks for your response. But I am looking to delete those lines which comes under the $lname variable. but your solution is only giving the lines name not what exectly I want.
009satya
# 4  
Old 11-14-2006
Code:
$ cat excl.dat
Input line 1
Input line 2
Input line 3
Input line 4
Input line 5
Input line 6
Input line 7
Input line 8
Input line 9
Input line 10
Input line 11
Input line 12
$ lname='1 5 7 10'
$ awk -v excl=" $lname " '! index(excl, " " NR " ")' excl.dat
Input line 2
Input line 3
Input line 4
Input line 6
Input line 8
Input line 9
Input line 11
Input line 12
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert a horizontal lines to vertical lines in a csv file

Hi.. I need some help in converting the below horizontal lines to vertical lines format. can anyone help me on this. input file Hour,1,2,3,4,5 90RT,106,111,111,112,111 output file Hour,90RT 1,106 2,111 3,111 4,112 5,111 (3 Replies)
Discussion started by: Raghuram717
3 Replies

2. Shell Programming and Scripting

Parsing a CSV file and deleting all rows on condition

Hello list, I am working on a csv file which contains two fields per record which contain IP addresses. What I am trying to do is find records which have identical fields(IP addresses) which occur 4(four) times, and if they do, delete all records with that specific identical field(ip address). ... (4 Replies)
Discussion started by: landossa
4 Replies

3. Shell Programming and Scripting

deleting lines from file

We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Discussion started by: daveisme
8 Replies

4. Shell Programming and Scripting

Deleting columns from CSV file

Hi All, Am working on perl script which should delete columns in existing CSV file. If my file is : AA,BB,CC,DD 00,11,22,33 00,55,66,77 00,99,88,21 AA,BB... are all my headers can come in any order (e.g AA,CC,BB...) and rest are values. I want to delete column CC... Can anybody help... (2 Replies)
Discussion started by: darshakraut
2 Replies

5. Shell Programming and Scripting

Deleting rows from csv file

Hello, I am supposed to process about 100 csv files. But these files have some extra lines at the bottom of the file. these extra lines start with a header for each column and then some values below. These lines are actually a summary of the actual data and not supposed to be processed. These... (8 Replies)
Discussion started by: cobroraj
8 Replies

6. UNIX for Dummies Questions & Answers

Deleting whole lines from a file

I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
Discussion started by: red baron
3 Replies

7. Shell Programming and Scripting

deleting rows & columns form a csv file

Hi , I want to delete some rows & columns from file. can someone please help me on this? Regards. (2 Replies)
Discussion started by: code19
2 Replies

8. Shell Programming and Scripting

Deleting lines in a file

How do I delete all the lines after the line containing text ***DISCLOSURES*** . I want to delete this line too. Thank you (2 Replies)
Discussion started by: reachsamir
2 Replies

9. Shell Programming and Scripting

Deleting last 2 lines from the file.

Hi I have a file & always I need to remove or delete last 2 lines from that file. So in a file if I have 10 lines then it should return me first 8 lines. Can someone help me? (4 Replies)
Discussion started by: videsh77
4 Replies

10. Shell Programming and Scripting

Deleting Lines from .CSV Files

I have written an script which will excluded some records from .csv file and put it on another excluded file from primary file.This is working very fine.Now the problem is that I want to delete those excluded lines from Primary file but not able to delete it. I have stored the line number in... (1 Reply)
Discussion started by: 009satya
1 Replies
Login or Register to Ask a Question