String Manipulation ${no.} meaning


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String Manipulation ${no.} meaning
# 1  
Old 07-24-2012
String Manipulation ${no.} meaning

File name is

Code:
INFILE="ABC_BMWPPI_20120909_00073.DAT.ASDFGHJK" -> 44 character long

mv INFILE GEPB_${INFILE:${#INFILE}-27:15}dat

result is GEPB_20120909_00073.DAT.

I am confused in how we get it.
If I evaluate
1- GEPB_${INFILE:${#INFILE}-27:15}dat
2- GEPB_${INFILE:${44}-27:15}dat
3- GEPB_${INFILE:14:15}dat
4- GEPB_20120909_00073.dat

Can anybody explain how ${44} got evaluated here?
generally $ comes with variable name, how it is working with number here.
Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 07-24-2012 at 01:57 PM..
# 2  
Old 07-24-2012
Assuming you're using bash, see -
String Length: Parameter expansion [Bash Hackers Wiki]
and directly beneath,
Substring expansion: Parameter expansion [Bash Hackers Wiki]

(NB: it appears formatting may have eaten some of your characters; from my count "ABC_BMWPPI_20120909_00073.DAT.ASDFGHJK" is only 38 chars long, so it's hard to reconcile this with the exact output you're getting since the numbers are off - the basic idea/concept is the same)
# 3  
Old 07-24-2012
${44} would be the 44'th commandline parameter, whatever that happens to be, not a number. Take this script:

Code:
#!/bin/sh

echo $1 $2 $3

Code:
$ ./myscript.sh a b c

a b c

$


Last edited by Corona688; 07-24-2012 at 02:06 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String manipulation.

If a have a variable with a first and last name. and say the variable looks like this... FIRST LAST how could process the variable to look like First .L bash 3.2 (osx) (3 Replies)
Discussion started by: briandanielz
3 Replies

2. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

3. Shell Programming and Scripting

string manipulation

Hi, I have the followoing details in one file: opt/tra/domain/test/new/filename1 training/ear/help I need to manipulate the string in the following manner: filename1= opt/tra/domain/test/new/filename1 help=training/ear/help last string is the name and equal sign and then... (2 Replies)
Discussion started by: ckchelladurai
2 Replies

4. Shell Programming and Scripting

string manipulation

hi all, i am new to shell scripting and need help. i have a string that stores the month in Jan/Feb/Mar format. i need to convert it to number like 01 for jan, 12 for dec etc. i am using the following sed command, echo "Enter a Month eg. Jan/Feb : " read MONTHEND ... (9 Replies)
Discussion started by: anupom2000
9 Replies

5. Shell Programming and Scripting

String manipulation

Hi All, Pls help me out on the below, 05 LAMSZ201-ZM-MEMO2-DATE02-5 PIC X(10). 05 LAMSZ201-ZM-MEMO2-AMT02-5 PIC S9(13)V99. 05 LAMSZ201-ZM-MEMO2-TYPE02-6 PIC XXX. 05 LAMSZ201-ZM-MEMO2-DATE02-6 PIC X(10). 05 ... (2 Replies)
Discussion started by: baskivs
2 Replies

6. UNIX for Dummies Questions & Answers

Help with String manipulation

Dear All, I have a question. I have files with the following pattern.>S8_SK1.chr01 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNNNNNNNNNNNNNCAGCATGCAATAAGGTGACATAGATATACCCACACACCACACCCTAACACTAACCCTAATCTAACCCTGGCCAACCTGTTT... (13 Replies)
Discussion started by: pawannoel
13 Replies

7. Homework & Coursework Questions

String Manipulation

Write a shell program to display the position of the right - most character in a given input string. Example : Input : RAHUL Output : L is in the 5th position also tell me how to count length of string and how to find the position of specific character in left most side. Homework... (0 Replies)
Discussion started by: shashwat2691
0 Replies

8. Shell Programming and Scripting

String Manipulation

Hi, I have a file in the following format 123|shanwer|15DEC2010|bgbh|okok|16JAN3000|okok| I want the following to be in following format 123|shanwer|12\15\2010|bgbh|okok|01\16\3000|okok| SED/PERL/AWK Gurus could you please help me with this? Thanks Shankar (8 Replies)
Discussion started by: Shan2210
8 Replies

9. UNIX for Dummies Questions & Answers

String manipulation

I am doing some training for a job I have just got and there is an exercise I am stuck with. I am not posting to ask a question about logic, just a trivial help with string manipulation. I would appreciate if somebody could at least give me a hint on how to do it. Basically, the intelligent part... (8 Replies)
Discussion started by: Dantastik
8 Replies

10. UNIX for Dummies Questions & Answers

string manipulation

Hi, I have a file with rows of text like so : E100005568374098100000015667 D100005568374032000000112682 H100005228374060800000002430 I need to grab just the last digits(bolded) of each line without the proceeding text/numbers. Thanks (5 Replies)
Discussion started by: james6
5 Replies
Login or Register to Ask a Question