Substring Function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substring Function
# 1  
Old 02-23-2007
Substring Function

Just so you know guys, I am a SAP Person and I am very new to UNIX. I need a help on a one line code.

In one of our script we are referring to a variable ($PN) which has the value /interfaces/DA1/DEV291/outbound/INVOIC which is being used in ftp command. I am just looking for a command to have a another variable which will have the substring of $PN.

Our Current Code
PN=$1
FILE=`echo $PN awk -F / '{print \$NF}'`

echo quote rcmd call CSP105 "('$PN' '02')" >> /interfaces/DA1/DEV291/outbound/$FILE

Needs to be replaced as
echo quote rcmd call CSP105 "('$XX' '02')" >> /interfaces/DA1/DEV291/outbound/$FILE

Right now the $PN is holding the value of /interfaces/DA1/DEV291/outbound/ our new variable XX should have the value of /DA1/DEV291/outbound/


Thanks,
Sasikumar
# 2  
Old 02-23-2007
Code:
xx="/"${pn#/*/}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies

2. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

3. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

4. UNIX for Dummies Questions & Answers

Substring Function

I have a file in which there are other file path and names /home/data/abc.txt /home/data/sdf.txt /home/data/sdg.txt how can I get the file names i.e. abc.txt sdf.txt sdg.txt I searched the forum for sed command but it was confusing to me (10 Replies)
Discussion started by: eskay
10 Replies

5. Shell Programming and Scripting

Substring a returned function value

Hello, I have something that should be very simple yet I am losing my head in figuring out how to get it to work: I am calling a function passing a parameter, this will return a particular string, next I want to substring the returned value and break it apart. All of this I want to do on a... (2 Replies)
Discussion started by: gio001
2 Replies

6. Linux

Selecting substring (like SQL Server function)

Hey, geniuses of the world (no--facetious is NOT the word of the day;))! I was wondering if there's a way to extract a specific portion from a string of characters in UNIX/LINUX. Give me the generic capabilities (assuming they exist) and I'll figure out the small details. But if you know... (8 Replies)
Discussion started by: ProGrammar
8 Replies

7. Shell Programming and Scripting

How to do String manipulations using Substring function in Shell

Hi, I have a scenario to just plug out the file name from the following location path. /opt/project/data/int/holdFiles/csv195687.csv So, how do I get just file name which is "csv195687.csv" from the above line using awk/shell scripting? Can we use indexOf and Substring in awk to get... (7 Replies)
Discussion started by: anilvvnn
7 Replies

8. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

9. UNIX for Dummies Questions & Answers

Substring function in UNIX shell script

Hi All, Following is the output of a find commnd to locate log directories for various projects of UNIX AIX box: /home/hbinz6pf/projectlibs/dpr_pfsdw_dev/&PH& /opt/tools/ds/Template/&PH& /data/ds/ms/hmsdw/projectlibs/dpr_ms_dev/&PH& /data/ds/riskmi/projectlibs/dpr_riskmi_dev/&PH&... (5 Replies)
Discussion started by: csrazdan
5 Replies

10. Shell Programming and Scripting

Substring function in UNIX shell script

Hi All, Following is the output of a find commnd to locate log directories for various projects of UNIX AIX box: /home/hbinz6pf/projectlibs/dpr_pfsdw_dev/&PH& /opt/tools/ds/Template/&PH& /data/ds/ms/hmsdw/projectlibs/dpr_ms_dev/&PH& /data/ds/riskmi/projectlibs/dpr_riskmi_dev/&PH&... (1 Reply)
Discussion started by: csrazdan
1 Replies
Login or Register to Ask a Question