1827304 Members
2931 Online
109961 Solutions
New Discussion

Re: HPUX commands?

 
Chin Meng
Occasional Advisor

HPUX commands?

Dear all,

What are the commands that can be used if I wanna to find certain words and then need to replace that words with the new words.

Example, testing1.txt. Inside the testing1.txt has many of "$HOSTNAME" I wanna to replace the "$HOSTNAME" to "$BAAN" for example.

I should used the command like find ./-name..?

Maybe I need the HPUX command for replace the word?

Thank you in advance for whom help me.
4 REPLIES 4
RikTytgat
Honored Contributor

Re: HPUX commands?

Hi,

To change text in a file, you should use 'sed'.

cat yourfile | sed -e 's/\$HOSTNAME/\$BAAN/g' > yourfile.new

should do the job. The 's' in the sed command means 'substitute' and the trailing 'g' means 'globally' (ie every occurence on a line).

The stuff between the slashes is what and to what you want to change.

See the sed(1) manpage for more info on sed and the regexp(5) manpage for info on regular expressions.

Hope this helps,
Rik

CHRIS_ANORUO
Honored Contributor

Re: HPUX commands?

Hi Use this line of sed to substitute:
cat yourfile | sed 's, \$HOSTNAME, i\ \$BAAN,g' > yourfile.new
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Wodisch
Honored Contributor

Re: HPUX commands?

Hello Chin,

why not using "ed"?

find . -exec ed -e '1,$s/\$HOSTNAME/\$BAAN/g' -e'1,$w' {} ";"

that should do the trick...

HTH,
Wodisch
Rick Garland
Honored Contributor

Re: HPUX commands?

I opt for the use of sed.

cat file | sed -e s/pattern1/pattern2/g > newfile