it prints to the screen instead of replacing the current string (username@email.com) with the string #username@email.com

how do i go about doing it?

thanks!

jkobrien

06-29-2004 04:24 AM

The code in my previous mail should be entered all on one line if you're doing it from the command line. To have the output go to a file, use a redirect "> NEWFILE".

Alternatively you can put all the code between the single quotes into a text file and then use the command as follows:

awk -f CODEFILE FILENAME > NEWFILE

John

topcat

06-29-2004 04:41 AM

Cant I do a replace without using an intermediary file? Because newfile needs to be renamed into file and this script is run as user apache (called via PHP).
So each time anything is done, such as renaming file, etc, the owner group is changed to root.root so the php script cannot act on it further.

This is why i needed something that can be done while keeping same file name..
like a replace command..

Step 1: Look for string email@domain.com:127.0.0.1:1
replace it with #email@domain.com:127.0.0.1:1

this will be called by php and the permissions, owner should remain same..

thanks!!

jkobrien

06-29-2004 05:13 AM

You can use 'chown' to change the ownership of a file, so your script would be something like this...

I have a same question, but with different pattern I have two files and the files have following lines

File-A
---------
A
B
C
D
E
F
G
H
I
J
K
L
M

File-B
-------
A
B
C
D
E

I want to delete the lines which are in File-B (A,,B,C,D,E) from File-A. I mean after executing the command the output of File-B would be F,G,H,I,J,K,L,M.

Please help me out in this.

Thanks,
Suraj

jkobrien

02-22-2007 05:58 AM

comm -13 File-A File-B > TEMP ; mv TEMP File-B

jr1

02-23-2007 02:35 PM

Quote:

Originally Posted by jkobrien

comm -13 File-A File-B > TEMP ; mv TEMP File-B

This will work for the example given by suraj_sharma1981 because the two files are both sorted in the same way (actually, it won't quite work because File-A and File-B appear to have gotten mixed up in Suraj's question). It won't necessarily work if the two files are sorted differently. For example

Code:

$ cat A
b
a
c
$ cat B
a
c
$ comm -13 B A
b
a

firstfire

02-23-2007 06:17 PM

Quote:

Originally Posted by topcat

Cant I do a replace without using an intermediary file? Because newfile needs to be renamed into file and this script is run as user apache (called via PHP).
So each time anything is done, such as renaming file, etc, the owner group is changed to root.root so the php script cannot act on it further.

This is why i needed something that can be done while keeping same file name..
like a replace command..

Step 1: Look for string email@domain.com:127.0.0.1:1
replace it with #email@domain.com:127.0.0.1:1

this will be called by php and the permissions, owner should remain same..

thanks!!

You can use `-i' flag in sed. One more interesting approach is to use the `ed' editor for doing changes in your file.
Here are simple examples: