LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-21-2008, 06:22 PM   #16
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 69

Quote:
Originally Posted by wondergirl View Post
is there some sort of limitation with sed with the numbers of itireation or something?????? I'm beating my head against the wall for this!
There may be some sort of limitation in your shell’s implementation of the for loop (how big is fileB?). Try this instead:
Code:
#!/bin/sh
while read i; do
  sed '/^'${i}'/d' fileA>newfile
  mv newfile fileA
  echo ${i}
done < fileB

Last edited by osor; 02-21-2008 at 08:18 PM.
 
Old 02-21-2008, 07:48 PM   #17
wondergirl
LQ Newbie
 
Registered: Feb 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor View Post
There may be some sort of limitation in your shell’s implementation of the for loop (how big is fileB?). Try this instead:
Code:
#!/bin/sh
while read; do
  sed '/^'${i}'/d' fileA>newfile
  mv newfile fileA
  echo ${i}
done < fileB
YAY!!! This works like a charm

Thanks so much for all the comments and help from all of you on this. The join command is interesting so I'm glad that was mentioned.

I didnt know there is a limitation on for loop in the shell....but apparently there is because the while loop works.
 
Old 02-21-2008, 08:18 PM   #18
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 69
Quote:
Originally Posted by wondergirl View Post
YAY!!! This works like a charm
Except of course that I made a typo . The first line should be:
Code:
while read i; do
 
Old 02-21-2008, 09:08 PM   #19
wondergirl
LQ Newbie
 
Registered: Feb 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor View Post
Except of course that I made a typo . The first line should be:
Code:
while read i; do
That is OK..I caught that and fixed it myself but the while made it work.
 
Old 02-21-2008, 11:22 PM   #20
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Quote:
Originally Posted by wondergirl View Post
That is OK
Thanks.

Quote:
Originally Posted by wondergirl View Post
What do you mean I can do join as long as its sorted? Trying to read about join but would appreciate if you can explain a bit more.
:cat file1
server1
server2
server3
server4
server5

:cat file2 # out of order
server4
server2

:join -v1 file1 file2
server1
server2
server3
server5

Guessing at the algorithm that requires the files to be sorted: file1's server4 and file2's server4 join, but we've already passed server2 in file1, so it's 'wrongly' (for our purposes) skipped when we get to it in file2.

:join -v1 <(sort file1) <(sort file2)
server1
server3
server5

With the files sorted, we exclude both the joined server4 and server2. (That second example uses process substitution and I don't know if that's supported on Solaris, but it's just an example.)

Hope that helps.
 
Old 02-22-2008, 02:06 AM   #21
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,459

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
Originally Posted by digiot View Post
That second example uses process substitution and I don't know if that's supported on Solaris, but it's just an example.
It does. It's more a shell feature than an OS one. Solaris has ksh, zsh and bash which all support process substitution.
 
Old 02-22-2008, 02:42 AM   #22
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Well, I was thinking it was system-dependent as well as a shell feature. Refreshing my memory with the bash manual, it states, "Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files", so it is but of course Solaris supports named pipes and possibly /dev/fd, too, so that was excessive compatibility paranoia.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed question krock923 Programming 2 04-30-2006 09:36 PM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
sed question provkitir Programming 4 05-03-2005 09:41 AM
sed question from Ch 6.12 na5m Linux From Scratch 1 02-02-2005 03:36 PM
sed question 360 Programming 2 03-15-2002 09:52 AM


All times are GMT -5. The time now is 01:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration