LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sed question (https://www.linuxquestions.org/questions/programming-9/sed-question-622700/)

osor 02-21-2008 06:22 PM

Quote:

Originally Posted by wondergirl (Post 3065527)
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


wondergirl 02-21-2008 07:48 PM

Quote:

Originally Posted by osor (Post 3065588)
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 :newbie:

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.

osor 02-21-2008 08:18 PM

Quote:

Originally Posted by wondergirl (Post 3065643)
YAY!!! This works like a charm

Except of course that I made a typo ;). The first line should be:
Code:

while read i; do

wondergirl 02-21-2008 09:08 PM

Quote:

Originally Posted by osor (Post 3065666)
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.

slakmagik 02-21-2008 11:22 PM

Quote:

Originally Posted by wondergirl (Post 3065018)
That is OK :)

Thanks. :)

Quote:

Originally Posted by wondergirl (Post 3065018)
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.

jlliagre 02-22-2008 02:06 AM

Quote:

Originally Posted by digiot (Post 3065778)
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.

slakmagik 02-22-2008 02:42 AM

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. :)


All times are GMT -5. The time now is 03:16 PM.