Visit Our UNIX and Linux User Community


Zero typing problem!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zero typing problem!
# 1  
Old 10-19-2012
Zero typing problem!

H,
I
I have this below script for removing the full path from a string which is indeed a filepath location if windows.
It converts input
\abc\asssh\abc
To
abc


But if filename has 0 like:
\abc\abc\00000Hgg
Then its typing
abc00000Hgg

PLEASE note that its solaris.
Script is:
more convertname.sh
Code:
#!/bin/sh
str=$@
echo $str | sed 's/.*\\//'
exit 0

# 2  
Old 10-19-2012
Strange!

You can use basename to get the last part of a path.

As sh means sh in Solaris, that's probably the easiest approach.

Edit: Seing that it's backslashes, not forward slashes, basename might not cut it, but I don't understand if those are normal (ASCII) zero's why sed would behave this way.

Edit 2: Duh! Because sed treats \0 as a Null character!

Edit 3: That was a duh @ me, not a duh @ you Smilie
# 3  
Old 10-19-2012
See if this works for you
Code:
str=$@
echo "$str" | tr -s '\' ' ' | nawk '{print $(NF)}'

# 4  
Old 10-19-2012
Try using double quotes..

Code:
#!/bin/sh
str=$@
echo "$str" | sed 's/.*\\//'
exit 0

@Jim

I think we can directly do like this also(Don't know is there any problem with SolarisSmilie)

Code:
echo "$str" | nawk -F '\' '{ print $NF}'

# 5  
Old 10-19-2012
The easiest way would be to do this:

Code:
$ echo ${str##*\\}
00000Hgg


Last edited by Subbeh; 10-19-2012 at 09:39 AM.. Reason: Oops, doesn't work with sh in Solaris :)
# 6  
Old 10-19-2012
Quote:
Originally Posted by Subbeh
The easiest way would be to do this:

Code:
$ echo ${str##*\\}
00000Hgg

Not in sh in Solaris it wouldn't Smilie
# 7  
Old 10-19-2012
Any solution guys!

Last edited by nixhead; 10-19-2012 at 10:48 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #885
Difficulty: Easy
Denial of service attacks (DoS) are designed to make a machine or network resource unavailable to its intended users.
True or False?

7 More Discussions You Might Find Interesting

1. HP-UX

@ typing creates new line

Dear Concern, Please go through the article https://www.unix.com/hp-ux/134072-typing-sign-creates-new-line.html As per the article, we need to initiate below commands. But after creating new session, we face same problem. Please advise. stty intr "^c" stty kill "^u" Please find below... (6 Replies)
Discussion started by: makauser
6 Replies

2. UNIX for Dummies Questions & Answers

No $ when typing cw

Hi As a dummy my question is very simple. When typing cw I've read (many times) that a '$' should appear at the end of the word I'm about to change. However, it doesn't, and in my case the word is instantly deleted and so ready to be changed! Can somebody tell me why this is, or maybe I... (4 Replies)
Discussion started by: joesh
4 Replies

3. UNIX for Advanced & Expert Users

Determining typing latency

Hi all, When I use an editor (vi) that is spawned in a remote server, visually I could see the latency between typing a character/word and being displayed on the terminal. I could see this visually but how do I get a metric on this or how to quantify this? As expected, when I type in a editor... (6 Replies)
Discussion started by: matrixmadhan
6 Replies

4. Shell Programming and Scripting

No output to CL when typing in CL.

Hello all, I am in a terminal on Solaris and something weird is happening... When I am typing I can't see what I am typing, although what I am typing is working. As is if I type the command and hit enter, the command runs. Anyone have a clue why or how I can make it display my typing? Is... (2 Replies)
Discussion started by: komputersman
2 Replies

5. UNIX and Linux Applications

Learn typing in Chinese

I have a burning desire to learn how to type in chinese (and after, probably with success, in another languages). How to do this, all symbols are needed, and methods of input also. And a map of chinese keyboar layout will be helpful. I want very much study program. (3 Replies)
Discussion started by: Xcislav
3 Replies

6. UNIX for Dummies Questions & Answers

Stuck after typing goto

uname -a returns: SMP Tue May 17 17:52:23 EDT 2005 i686 athlon i386 GNU/Linux I have many aliases beginning with "goto" so... if I type goto and then hit return (oops) A goto prompt pops up and I cant exit from it(I tried MANY key seqs) The only way to exit is to kill the term window... (2 Replies)
Discussion started by: rairey
2 Replies

7. UNIX for Advanced & Expert Users

Hiding Passwords while typing..

Hi, We need ur advice,... We are integrating our application (oracle) with OID,and OID is with another team. While integrating they have to provide their 'ADMIN-password' when the script prompts ,But the password they are about type is visible. If this is the case they are denying it,.... Is... (1 Reply)
Discussion started by: rrs
1 Replies

Featured Tech Videos