Networking Forums

Networking Forums > Computer Networking > Linux Networking > Issues with ftpaccess and Fgrep

Reply
Thread Tools Display Modes

Issues with ftpaccess and Fgrep

 
 
Skyggen
Guest
Posts: n/a

 
      10-20-2003, 07:22 AM
Ok, I am attempting to append to the middle of a file. I am not
interested in appending to the end I know how to do that. Here is what
I havepart of user add script)

tail -55 ftpaccess > efile
fgrep -v -f efile ftpaccess > sfile

What happens is that sfile has no output in it, it is empty which
drive me insane becaue this works with every file I have tried except
ftpaccess.
 
Reply With Quote
 
 
 
 
Alan Connor
Guest
Posts: n/a

 
      10-20-2003, 07:59 AM
On 20 Oct 2003 00:22:53 -0700, Skyggen <(E-Mail Removed)> wrote:
>
>
> Ok, I am attempting to append to the middle of a file. I am not
> interested in appending to the end I know how to do that. Here is what
> I havepart of user add script)
>
> tail -55 ftpaccess > efile
> fgrep -v -f efile ftpaccess > sfile
>
> What happens is that sfile has no output in it, it is empty which
> drive me insane becaue this works with every file I have tried except
> ftpaccess.


That's pretty clever, and I can't see why it wouldn't yield the first lines
of ftpaccess...Unless there were less than 55 lines in the file (?).

But there are other ways of inserting text in the middle of a file.

If you wanted to read in file foo at line 56, then you could do

sed '55r foo' file > tmpfile
mv tmpfile file

Or if there was a unique string just before you wanted to insert the file:

sed '/regex/r foo' etc

to put the file before a line with a unique string

sed '/regex/i\
line one\
line two\
' file > tmpfile etc

Best to put that last one in a file (what's between the ' and without them)

sed -f scriptfile file > tmpfile etc

--
Alan C
Posts with sigs of > 4 lines, or not in plain text, are dumped by my filters.
 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a

 
      10-20-2003, 08:26 AM
Skyggen wrote:

> Ok, I am attempting to append to the middle of a file. I am not
> interested in appending to the end I know how to do that. Here is what
> I havepart of user add script)
>
> tail -55 ftpaccess > efile
> fgrep -v -f efile ftpaccess > sfile
>
> What happens is that sfile has no output in it, it is empty which
> drive me insane becaue this works with every file I have tried except
> ftpaccess.


What are you trying to do again? "fgrep" wants to find a matching pattern,
and you're providing an entire file of patterns for it to match. This is
going to run very slowly, because each of the lines in the pattern file has
to be matched sequentially with each of the lines in the data file until a
match is found. In other words, the search time increases as the number of
lines in the pattern file TIMES the number of lines in the target file.

There are MUCH easier, faster ways to accomplish anything you can name.
Apart from the fact that your method doesn't work reliably.

Instead of trying to explain your solution, just tell us what you want to
do, and why.

Perl, as just one example, can split a file on an arbitrary search pattern,
and you could use this property to insert any arbitrary length of insertion
text at the location of the pattern match, creating the insertion you
apparently want -- but MUCH more efficiently than the above.

--
Paul Lutus
http://www.arachnoid.com

 
Reply With Quote
 
Skyggen
Guest
Posts: n/a

 
      10-20-2003, 05:16 PM
>Paul Lutus <(E-Mail Removed)> wrote in message >news:<(E-Mail Removed)>...
>> Skyggen wrote:
>>
>> > Ok, I am attempting to append to the middle of a file. I am not
>> > interested in appending to the end I know how to do that. Here is

what
>> > I havepart of user add script)
>> >
>> > tail -55 ftpaccess > efile
>> > fgrep -v -f efile ftpaccess > sfile
>> >
>> > What happens is that sfile has no output in it, it is empty which
>> > drive me insane becaue this works with every file I have tried

except
>> > ftpaccess.

>>
>> What are you trying to do again? "fgrep" wants to find a matching

pattern,
>> and you're providing an entire file of patterns for it to match.

This is
>> going to run very slowly, because each of the lines in the pattern

file has
>> to be matched sequentially with each of the lines in the data file

until a
>> match is found. In other words, the search time increases as the

number of
>> lines in the pattern file TIMES the number of lines in the target

file.
>>
>> There are MUCH easier, faster ways to accomplish anything you can

name.
>> Apart from the fact that your method doesn't work reliably.
>>
>> Instead of trying to explain your solution, just tell us what you

want to
>> do, and why.
>>
>> Perl, as just one example, can split a file on an arbitrary search

pattern,
>> and you could use this property to insert any arbitrary length of

insertion
>> text at the location of the pattern match, creating the insertion

you
>> apparently want -- but MUCH more efficiently than the above.


I am looking for a script in bash to add lines to any part of a file.
I know of easy ways. I even had a C programmer offer to write a small
program, but out of interest to see how it could be done in bash.
 
Reply With Quote
 
Paul Lutus
Guest
Posts: n/a

 
      10-20-2003, 06:20 PM
Skyggen wrote:

< snip >

> I am looking for a script in bash to add lines to any part of a file.
> I know of easy ways.


Hmm. This seems to be contradicted by your prior post. The method you posted
is (1) not easy, is (2) really slow, and (3) according to your report,
doesn't work.

> I even had a C programmer offer to write a small
> program, but out of interest to see how it could be done in bash.


Use Perl regexp to split the file using a unique string and insert the
desired content at the located insertion point.

But that is only one of dozens of ways to do it.

Try this. Use WC to count lines:

total=(`wc -l filename`)

Split the line count into two values:

let bottom=total/2

let top=total-bottom

Use these values to split the file:

tail -$top filename > topfile

head -$bottom filename > bottomfile

cat bottomfile insertfile topfile > newfile

But there are too many ways to list, all better than the original idea, to
accomplish this.

--
Paul Lutus
http://www.arachnoid.com

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
WPA issues after SP3 plynch Wireless Networks 2 12-03-2008 06:43 PM
are MSN and AOL having issues w / each other? Got Any Gum? Windows Networking 1 03-31-2006 04:50 PM
Mn-710 issues Sam Broadband Hardware 0 07-06-2004 03:05 AM
PPTP issues including issues with routing Sameer Windows Networking 0 04-27-2004 05:06 AM
vsftpd - chown on upload (Q: migrating "upload" directive from wu_ftpd ftpaccess) Gerald Klaas Linux Networking 0 09-08-2003 06:51 PM



1 2 3 4 5 6 7 8 9 10 11