sed or awk

Hi all,

Been a long while since I've been here and the changes look great.:b:

Have a simple task that has been raised due to meeting PCI AND ISO standards. We currently keep a copy of all FTP/SFTP batch scripts just in case we need to view them, they are overwritten with each run, but we still keep them.

These files as a result contain UID's & PWD's. Meeting with the standards, I'd like to include a simple sed or awk statement that replaces each line of the said batch scripts beginning with 'user' to 'user **** ****'. Replacing the UID & PWD.

This would occur immediately after the batch script is used and satisfy our requirement.

Which is easier to use to acomplish this -- sed or awk ??

Cheers,
Cameron

In my mind sed is better. It is depand on your teaste :):D:p

Thanks
Sanjay Tripathi

In that case I would use a Perl structure , ex:

perl -pi -e "s/user/user name/g" script_files*

yes, its been a while, your first post is in 2005.

from 2005 till now, which one of them are you working more comfortably with? use that.

Many thanks SanjayLinux, Klashxx & ghostdog74 for your replies.

Sanjay - too true - I used to remember using sed many years ago. Just been too long now. :o

Klashxx - thanks for the perl example, though my requirement isn't a case of plain substitution; rather replacement of the entire line. :wink:

ghostdog74 - yep a while has past since I first joined the forum. Was surprised I could even remember my UID & PWD for the site. Unfortunately because of my involvement in PCI and ISO work, I've not had much opportunity for sometime or a reason to use sed, let alone look at awk. :frowning:

I was able to perform what I wanted to do via the command line, but would like to know how can I contain the following to a single-line command statement ??

$ sed '
> /^user/ c\
> user **** ****
> ' temp.txt

INPUT FILE:
user UID1 PWD1
user UID2 PWD2
user UID3 PWD3
get blah-blah-blah
close
bye

OUTPUT:
user **** ****
user **** ****
user **** ****
get blah
close
bye

Thanks in advance if you are able to assist with my query.

Cheers,
Cameron

just put everything on a single line?

You'll need to excuse my ignorance, but how you would you format the statement in one line ??
I'd tried a number of variations with no success.

Hi ghostdog & everyone,

Have been trying variations of:

sed '/^user/ c /user **** ****/ ' ${BATCHFILE} > ${BATCHFILE}.tmp
mv ${BATCHFILE}.tmp > ${BATCHFILE}

sed '/^user/ c \"user **** ****\" ' ${BATCHFILE} > ${BATCHFILE}.tmp

With as yet no success. Returns the following:

sed: Function /^user/ c /user **** ****/ cannot be parsed.

Sorry, but how do you guys do it ?? :wink:

sed -e "s/^user.*/user **** ****/g" input.txt > input.txt.masked
mv input.txt.masked input.txt

Vino,
Many thanks for the ultra quick reply & your assist. :b:
I take it that the period [.] in '.*' has special significance ?

I didn't realise that I could perform a substitute like that.

Cheers,
Cameron

In the sed world, you can consider . as a placeholder for any character. And a .* would stand for any combination of characters.

Many thanks again Vino for the quick reply and the small lesson in 'sed' :wink:

Cheers,
Cameron