Cutting characters in a variable

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting characters in a variable
# 1  
Old 11-12-2009
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
# 2  
Old 11-12-2009
Homework ?..

anyway , something like this :

echo "ABCDEFDH" | cut -c5-8

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assiging to a variable after cutting from the input line

Hi all, I am reading from the file having entries like below 111.ABC.POT 6477.YHT.OIT Now I need to read each line and cut each line seperated by dot and print into the file . I tried below and it is not working . Please help while read READLINE do eval... (4 Replies)
Discussion started by: Hypesslearner
4 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

Cutting a string and storing it in a variable

Hello I have a script: path=test1 echo "${path%?}" till this the program is successful in deleting hte last character i.e. "1" and displays an output --> test. After this how can i save this output to another variable. (2 Replies)
Discussion started by: Kishore920
2 Replies

4. 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

5. UNIX for Advanced & Expert Users

Bash shell: Cutting pasting only parts of the name of a directory into a variable

I have a script in a directory and want to search the directory before like follows: i=0 for file in ../HN_* do echo $file ((i+=1)) echo $i done Currently I get following output: ../HN_2 1 ../HN_3 2 (2 Replies)
Discussion started by: ABE2202
2 Replies

6. Shell Programming and Scripting

Trouble cutting characters into a string.

I just have a couple of quick questions. I am having trouble with this cut. I am basically trying to cut the string so that i can insert the users guess at the appropriate point in the string. $letters is the character count of the $word. What it seems to do is cut the character into the... (0 Replies)
Discussion started by: Makaer
0 Replies

7. Shell Programming and Scripting

Cutting last few characters of file name

Dear Friends, Here I have two queries. 1. Want to make folder named as last three characters of a file name (length of file name can vary file to file) E.g File name is AAAACCCCBBBB.txt (12 Characters excluding file extension) then folder to be created is BBB Irrespective of... (7 Replies)
Discussion started by: anushree.a
7 Replies

8. UNIX for Dummies Questions & Answers

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. (6 Replies)
Discussion started by: ithirak17
6 Replies

9. AIX

CUT command - cutting characters from end of string

Hello, I need to delete the final few characters from a parameter leaving just the first few. However, the characters which need to remain will not always be a string of the same length. For instance, the parameter will be passed as BN_HSBC_NTRS/hub_mth_ifce.sf. I only need the bit before the... (2 Replies)
Discussion started by: JWilliams
2 Replies
Login or Register to Ask a Question