The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting lines from a file Nirgude07 UNIX for Advanced & Expert Users 11 07-01-2009 02:09 PM
Deleting lines in text file hern14 UNIX for Dummies Questions & Answers 5 05-16-2008 03:03 PM
Deleting lines in a file reachsamir Shell Programming and Scripting 2 05-29-2007 11:17 AM
Deleting last 2 lines from the file. videsh77 Shell Programming and Scripting 4 04-06-2007 01:14 PM
deleting lines in a log file BG_JrAdmin Shell Programming and Scripting 2 08-22-2006 11:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-13-2006
009satya
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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.
  #2 (permalink)  
Old 11-13-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
A possible solution using awk :
Code:
awk -v excl=" $lname " '! index(excl, " " NR " ")' csv_file

Jean-Pierre.
  #3 (permalink)  
Old 11-13-2006
009satya
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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.
  #4 (permalink)  
Old 11-14-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
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
$
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0