- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- change character with "/" in a file
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
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
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
11-07-2011 07:08 AM
11-07-2011 07:08 AM
hello,
what is the best way to change characters with "/" ( like a HPUX Volume Group ) in a file and also preserve the file permission, file owner ....
sed, awk or perl ?
i have some examples:
fs_act_vg=/dev/vgact
fs_new_vg=/dev/vgnew
SED:
sed "s|^/dev/${fs_act_vg}|/dev/${fs_new_vg}|g" file > file_new
cp file_new file
AWK:
but no finished ...
awk -v fs_act_vg="/dev/${fs_act_vg}" -v fs_new_vg="/dev/${fs_new_vg}" '$0 ~ fs_act_vg {print sub( $0,fs_act_vg,fs_new_vg) }' file > file_new
cp file_new file
PERL
perl -i.old -p -e "s/\/dev\/${fs_act_vg}/\/dev\/${fs_new_vg}/ if /\/dev\/${fs_act_vg}/" file
regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2011 01:36 PM
11-07-2011 01:36 PM
Re: change character with "/" in a file
Hi:
The best way? Define "best" --- shortest number of characters? Readability (assuming you know each language)? Smallest number of processes? Smallest process footprint? Speed?
By the way, you can golf your perl script to eliminate the toothpicks (escaped forward slash characters) by changing the delimiter from '/' to balanced pairs of angle, round, square or curly brackets.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2011 12:45 AM
11-08-2011 12:45 AM
Re: change character with "/" in a file
The best way? Define "best" --- shortest number of characters? Readability (assuming you know each language)?
i know very well "sed", "awk" but when i want to change a content in a file , i always must work with a temporary file ? a colleague ( he didn't work in our company) change "sed" to "perl" because we had some problems with "sed" and temporary files. so i think "perl" one liner are a good alternative ?
improvment : ( a better way for "if" i didn't find )
perl -i.old -p -e "s |/dev/${fs_act_vg}|/dev/${fs_new_vg}| if /\/dev\/${fs_act_vg}/ "
regards
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2011 05:04 AM
11-08-2011 05:04 AM
SolutionHi (again):
The GNU 'sed' offers in-place editing akin to Perl. The use of 'awk' wold require a temporary file.
perl -i.old -p -e "s |/dev/${fs_act_vg}|/dev/${fs_new_vg}| if /\/dev\/${fs_act_vg}/ "
...does not need the 'if' condition. The substitution will occur only if there is a match of the first operand, so:
perl -pi.old -e "s|/dev/${fs_act_vg}|/dev/${fs_new_vg}|"
Regards!
...JRF...