To get the characters from a variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers To get the characters from a variable
# 1  
Old 03-06-2008
Bug To get the characters from a variable

Hi ,
I need to get the specified word from the variable.can some one help me out in this ?
input=ASD34567P

i need to get the value as :

output1=34567


So i need to ignore the last character and get the remaining values.

THANKS IN ADVANCE.
# 2  
Old 03-06-2008
Quote:
Originally Posted by ithirak17
Hi ,
I need to get the specified word from the variable.can some one help me out in this ?
input=ASD34567P

i need to get the value as :
output1=34567

So i need to ignore the last character and get the remaining values.
Given the expected output and your requirement that the last character should be dropped, the outputs dont match.
34567 vs ASD34567
# 3  
Old 03-06-2008
Sorry i need to drop first three characters 34567.... and the last character also...
# 4  
Old 03-06-2008
Quote:
Originally Posted by ithirak17
Sorry i need to drop first three characters 34567.... and the last character also...
Is it always the first 3 characters and the last or you want the alphabets alone to be dropped ?
# 5  
Old 03-06-2008
Java

yes Vino ....i need to drop the first three characters and the last character. it is afixed format so .. i need to get that number.
# 6  
Old 03-06-2008
Quote:
Originally Posted by ithirak17
yes Vino ....i need to drop the first three characters and the last character. it is afixed format so .. i need to get that number.
You can start with this

Code:
output1=$(echo $input | sed -e "s/^...\(.*\).$/\1/g")

# 7  
Old 03-06-2008
Thanks vino....It working fine.I am not awware of sed can u please explain what this command will do?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Escape characters in a variable

Debian 9 64x - LXDE How can i disable escape sequences in a variable? #!/bin/bash #mainscript . "./links.bash" echo "$red_start This text should be red $color_end"#!/bin/bash #links.bash #colors red_start="\eOutput that i get: \e Output expected: This text should be... (5 Replies)
Discussion started by: int3g3r
5 Replies

2. Shell Programming and Scripting

Get first four characters from the variable name

Hi all I have a variable name as below runbatch=FCSTworLOADfx_CYR Now i need to search for FCST in this variable and run a program I am doing like this but it is failing if ; then ****RUN PROGRAM** Please help DJ Please use CODE tags when displaying sample input,... (3 Replies)
Discussion started by: Hypesslearner
3 Replies

3. Shell Programming and Scripting

[Solved] Count characters of variable from right

My variable is something like: f="/Volumes/VERVE/MOOTON_CALL/01_shots/XX/xx0195/Projects/program/rs0195_v400001.aep" I use ${f:63:6} to call "rs0195" as characters counted from the left, but it'd be so much easier to count from the right. If ${f:95:10} counts from the left, what would... (2 Replies)
Discussion started by: scribling
2 Replies

4. Shell Programming and Scripting

Unset variable with characters in value

I have a script with a $PASSWORD variable. I unset it right after using it, just to minimize the chance it could be left around for a snooper. That worked just fine... until I used a password with a value of "P@ssw0rd" Now, unset (even with -f, even with the variable enquoted) tells me: unset:... (1 Reply)
Discussion started by: jnojr
1 Replies

5. Shell Programming and Scripting

Variable being stored with additional characters

I am trying to store a string value to a temporary variable within my script. When I run the command manually it returns the expected value, but from the script an additional "\r" is at the end. tCurrentStatus=`cat ${tPC_status} | grep 'Current status' | awk '{print $NF}'` output: cat... (1 Reply)
Discussion started by: jxrst
1 Replies

6. Shell Programming and Scripting

getting first two characters of variable

From a shell script, I'm trying to get the first two characters of an environment variable. If I type at the command promot: XX=`echo $MYVAR | cut -c1-2` echo $XX It works just fine However, if I execute the exact same thing from a shell script, I get: cut: you must specify a list of... (2 Replies)
Discussion started by: Boomn4x4
2 Replies

7. Shell Programming and Scripting

Cut last 7 characters of a variable

I need to cut the last seven characters of a variable length variable. The variable may be 7 characters or 70. I need to always be able to grab the last 7 characters. I looked at the cut command but it always seems to want to start at the beginning of a line, not the end and count backwards. ... (5 Replies)
Discussion started by: kblawson14
5 Replies

8. Shell Programming and Scripting

Stripping characters from a variable

I'm using a shell script to get user input with this command: read UserInput I would then like to take the "UserInput" variable and strip out all of the following characters, regardless of where they appear in the variable or how many occurrences there are: \/":|<>+=;,?*@ I'm not sure... (5 Replies)
Discussion started by: nrogers64
5 Replies

9. Shell Programming and Scripting

Cutting characters in a variable

I have a variable var which contains "ABCDEFDH" Now I have to remove the first 4 characters that is "ABCD" so my variable should contain only "DEFH" plzz tell me how to do that . i am using bash shell (1 Reply)
Discussion started by: cynosure2009
1 Replies

10. UNIX for Dummies Questions & Answers

extract characters from a variable

Hi All, I have scenario as below, I want to cut the characters and store it variable2.. and want to display the variable2.. as shown below... eg: the size may differs , i am show just an example..... numbers are not fixed in variable1..i want to extract characters and... (1 Reply)
Discussion started by: G.K.K
1 Replies
Login or Register to Ask a Question