Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2008
Registered User
 

Join Date: Jan 2008
Location: Chicago
Posts: 78
delete multiple lines by line number

I have been googling, but cannot find that works for me.

I have a text file tmp.out with contents:

sadfsdf sdfosuidhfousdhof soduhf osdfu osudfhosudhfd
sdfgsdfg
asdfiojhsdf asdoludhflsdjfhskldjfhsdjdlfsjdhnlj h sdja
ouahsdjdafkljsa
oljhljh

I have another file tmp_memrecno.dat that has numbers:
5
3

I want to delete lines (read from tmp_memrecno.dat) from file tmp.out.

Here is what I have so far, but doesn't really work:

while read line
do
sed "$line"'d' test.out > tmp.out
done < tmp_memrecno.dat

Basically, the end result of file test.out should be
sadfsdf sdfosuidhfousdhof soduhf osdfu osudfhosudhfd
sdfgsdfg
ouahsdjdafkljsa
Sponsored Links
  #2 (permalink)  
Old 10-24-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,156
one way -

Code:
awk ' FILENAME=="tmp_memrecno.dat" { arr[$0]=1}
        FILENAME=="tmp.out" {
              if( FNR in arr){ continue}
              print $0
        } ' tmp_memrecno.dat  tmp.out > tmp.newfile


Last edited by jim mcnamara; 10-24-2008 at 03:44 PM..
  #3 (permalink)  
Old 10-24-2008
Registered User
 

Join Date: Jan 2008
Location: Chicago
Posts: 78
Quote:
Originally Posted by jim mcnamara View Post
one way -

Code:
awk ' FILENAME=="tmp_memrecno.dat" { arr[$0]=1}
        FILENAME=="tmp.out" {
              if( FNR in arr){ continue}
              print $0
        }  tmp_memrecno.dat  tmp.out > tmp.newfile

This prints an error:

Syntax Error The source line is 5.
The error context is
} >>> tmp_memrecno. <<< dat tmp.out > tmp.newfile
awk: 0602-500 Quitting The source line is 5.
  #4 (permalink)  
Old 10-24-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,156
See the edit above
  #5 (permalink)  
Old 10-24-2008
Registered User
 

Join Date: Jan 2008
Location: Chicago
Posts: 78
Thanks dude... you are the best.

- CB
  #6 (permalink)  
Old 10-24-2008
Registered User
 

Join Date: Jan 2008
Location: Chicago
Posts: 78
How would you use unix variables (tmp1=tmp_memrecno.dat and tmp2=tmp.out) in awk; for example $tmp1 and $tmp2.
  #7 (permalink)  
Old 10-24-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,156

Code:
awk -v tmp1="$tmp1" -v tmp2="$tmp2" ' {  print tmp1, tmp2} '  somefile

Sponsored Links
Closed Thread

Bookmarks

Tags
unix commands

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
regex to delete multiple blank lines in a file? fedora Shell Programming and Scripting 6 10-11-2007 05:36 PM
Need to delete multiple lines in a file. kangdom Shell Programming and Scripting 6 10-16-2006 12:02 PM
delete multiple empty lines whatisthis Shell Programming and Scripting 3 11-09-2005 05:42 PM
Delete multiple lines w/ sed bookoo Shell Programming and Scripting 2 07-25-2003 11:03 AM



All times are GMT -4. The time now is 06:12 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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0