- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need script to replace "/" with "\"
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
Forums
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
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
04-20-2004 11:05 PM
04-20-2004 11:05 PM
need script to replace "/" with "\"
I need to do the following I need a script that will change /aaaa/bbbb/cccc to \aaaa\bbbb\ccccc I have tried sed 's///\/g' and awk FS = / OFS = \ any suggestions, I need to keep away from perl so is there an easy way to perform this.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:09 PM
04-20-2004 11:09 PM
Re: need script to replace "/" with "\"
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:10 PM
04-20-2004 11:10 PM
Re: need script to replace "/" with "\"
sed 's/\//\\/g'
will work for you. If you use gnu-sed (the linux one) you can do it clearly using any character instead of \
eg sed 's|\/|\\|g'
Peace, R.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:11 PM
04-20-2004 11:11 PM
Re: need script to replace "/" with "\"
# tr '\\' /
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:13 PM
04-20-2004 11:13 PM
Re: need script to replace "/" with "\"
echo /aaaa/bbbb/cccc | sed 's%\/%\\%g'
HTH,
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:15 PM
04-20-2004 11:15 PM
Re: need script to replace "/" with "\"
# STRING="/aaaa/bbbb/cccc"
# echo "$STRING" | tr "[\057]" "[\134]"
\aaaa\bbbb\cccc
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:16 PM
04-20-2004 11:16 PM
Re: need script to replace "/" with "\"
# tr / '\\'
See that perl is not always the best tool?
Enjoy, Have FUN! H.Merijn [ using the right tool for the right problem ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:25 PM
04-20-2004 11:25 PM
Re: need script to replace "/" with "\"
Regds,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:30 PM
04-20-2004 11:30 PM
Re: need script to replace "/" with "\"
a5:/u/usr/merijn 101 > ksh
$ echo /aaa/bbb/ccc | sed -e "s;/;\;g"
sed: -e expression #1, char 7: Unterminated `s' command
$
Enjoy, Have FUN! H.Merijn [ who thinks sed is not the right tool here ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:48 PM
04-20-2004 11:48 PM
Re: need script to replace "/" with "\"
prc60b03:/root # timex echo aa/ss | sed 's%\/%\\%g'
real 0.00
user 0.00
sys 0.00
aa\ss
prc60b03:/root # timex echo aa/ss | tr / '\\'
real 0.01
user 0.00
sys 0.00
aa\ss
Who is just curious about why exactly tr is the better tool over sed.
Gideon ( 0 points please )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 12:02 AM
04-21-2004 12:02 AM
Re: need script to replace "/" with "\"
Just did the same with the a large file on a slow server and tr was faster. So i must admit your are right.
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 12:06 AM
04-21-2004 12:06 AM
Re: need script to replace "/" with "\"
lt09:/home/merijn 182 > > test.txt
lt09:/home/merijn 183 > repeat 5000 echo /what/if/there/are/more/lines >> test.txt
lt09:/home/merijn 184 > time tr / '\\'
0.001u 0.000s 0:00.00 0.0% 0+0k 0+0io 127pf+0w
lt09:/home/merijn 185 > time tr / '\\' < test.txt > /dev/null
0.000u 0.002s 0:00.00 0.0% 0+0k 0+0io 127pf+0w
lt09:/home/merijn 186 > time sed 's:/:\\:g'
0.059u 0.001s 0:00.05 100.0% 0+0k 0+0io 142pf+0w
lt09:/home/merijn 187 > time sed 's:/:\\:g' < test.txt > /dev/null
0.060u 0.001s 0:00.06 100.0% 0+0k 0+0io 142pf+0w
lt09:/home/merijn 188 >
Plainly shows that tr is faster
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 12:07 AM
04-21-2004 12:07 AM
Re: need script to replace "/" with "\"
awk '{gsub("/","\\");print}'
For the performance freaks, do it like this:
timex awk '{gsub("/","\\");print}' /tmp/tmpf
This gives better info as in Gideon's post, because in those you're only timing the echo or cat, not the command doing the substitions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 12:28 AM
04-21-2004 12:28 AM
Re: need script to replace "/" with "\"
To keep the substitute code clear and readable, use another symbol :
s@pattern@substitute@
rather than
s/pattern/substitute/
)
My 2 cents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 01:08 AM
04-21-2004 01:08 AM
Re: need script to replace "/" with "\"
It works for me in AIX , just tried the same in BASH and KSH of Linux it gave me the same error !
That means there are diffrences in every Vendor's implementation of shells ?
Regds,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 01:13 AM
04-21-2004 01:13 AM
Re: need script to replace "/" with "\"
Of course there are. IBM think they are the only truth, and so do M$.
Standards = multiple versions of the truth
I'm not surprised at all. Try all machines in HP/Compaq's test park. And Solaris, Primos, FreeBSD, OS/2, ...
I et they all act different
Enjoy, Have FUN! H.Merijn [ whose job in the Perl community is to know about these differences ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 01:22 AM
04-21-2004 01:22 AM
Re: need script to replace "/" with "\"
So that means if I have to migrate a script which I have on AIX to HPUX I would need to break by head looking at each shell command !!!
Thanks alot.
Regds,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 01:26 AM
04-21-2004 01:26 AM
Re: need script to replace "/" with "\"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 01:30 AM
04-21-2004 01:30 AM
Re: need script to replace "/" with "\"
To get the ksh to print his revision number, try [ESC] then [CTRL]V .
Version M-12/28/93d
Cheers,
Nicolas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 02:07 AM
04-21-2004 02:07 AM
Re: need script to replace "/" with "\"
If you type :
echo value | read var
var will be empty, no value has been assigned to it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 10:32 AM
04-21-2004 10:32 AM
Re: need script to replace "/" with "\"
Problems can arise with the '/' as sed will treat this as a seperator in your sed statement.
Change the '/' to a ',' :-
sed ,/,\,g
Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 06:19 PM
04-21-2004 06:19 PM
Re: need script to replace "/" with "\"
The easiest is via the most powerfull editior vi ,
vi the file you wanna change
in the Esc mode
:%s/\/..../\\..../g
....=> can be the length of the string you wanna replace .