- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed brainstorming
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2003 05:18 AM
тАО08-28-2003 05:18 AM
Hi all,
I need to add in a lots of .profile one line which is:
export ECRAN=`who am I -R | sed 's/.*(\([a-zA-Z0-9]*\)\..*/\1/'`
(the line must be insert before a match)
I search a good script using sed or awk which looks like that:
for i in [ .. . profile] ; do
sed 's/match/iexport ECRAN=`....' $i
done
this one didn't work because there are many special char in the string :
Maybe someone can help me.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2003 05:22 AM
тАО08-28-2003 05:22 AM
Re: sed brainstorming
you will need to spool the .profile files either in memory or to a temp file.
send what you want done than I'll code it for you.
life is good here
Donny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2003 05:39 AM
тАО08-28-2003 05:39 AM
Solutionkeep your loop
add a match command for these .profile
and
vi .profile
with mycom :
/
:r tpl1
:wq
and tpl1 is :
export ECRAN=`who am I -R | sed 's/.*(\([a-zA-Z0-9]*\)\..*/\1/'`
Of course if you navigate in subdir you would have to give full path for these files.
this will add the comand lie after the 1st match.
If none it would add the line on top of your .profile so better if you check beforehand with say "grep"
It's all yours
Rgds.
JL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2003 06:25 AM
тАО08-28-2003 06:25 AM
Re: sed brainstorming
for i in /home/*/.profile ; do
perl -p -i -e 'print "export ECRAN=\`who am I -R | sed \'s/.*(\\([a-zA-Z0-9]*\)\..*/\1/\'\`\n" if /match/'
done
This will insert the "export" line prior to any line that contains the text "match". I had to add extra "\" to the export so that perl would pass the characters asis. They of course will disappear in the resultant file.
The a nifty option to perl is called in-place changes. The -i option automatically creates a temp file, and sends the output there. At the end of the process, perl will make the temp file the "new" file. You also have the option to rename the original, ie -i.bu will rename original by appending ".bu".
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2003 06:26 AM
тАО08-28-2003 06:26 AM
Re: sed brainstorming
for i in /home/*/.profile ; do
perl -p -i -e 'print "export ECRAN=\`who am I -R | sed \'s/.*(\\([a-zA-Z0-9]*\)\..*/\1/\'\`\n" if /match/' $i
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2003 06:35 AM
тАО08-28-2003 06:35 AM
Re: sed brainstorming
Here's one possible way with 'awk' and a shell wrapper:
#!/usr/bin/sh
EXP="export ECRAN=\`who am I -R | sed 's/.*(\([a-zA-Z0-9]*\)\..*/\1/'\`"
awk -v EXP="${EXP}" '
BEGIN{ B=0 }
/PATH=/ {
if (B==0) { B=1;print EXP }
}
{print $0}
' $1 > $1.new
exit 0
NOTE that the "ticks" are escaped with the backslash in the 'EXP' variable assignment. Pass the name of the user's profile to the shell script. The modified file is titled the same with a ".new" extension.
I chose to insert the export before the first PATH declaration. You could do it anywhere.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2003 01:12 AM
тАО08-29-2003 01:12 AM
Re: sed brainstorming
This makes maintenance a little easier, in case you need to make a change in the future.