Slash delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Slash delimiter
# 1  
Old 12-11-2012
Slash delimiter

I have a log file which on field $11 there is sth like: /A/B/C and I want to extract the last part which is C.
for space delimiter I used:
Code:
awk '{print $2 " " $5 ";" $7 ";" $9 ";" $11}'

and had no problem.
but dont know how to extract the 3rd part of the slash delimiter.

That would be great if someone can help me in an easy way as I am just a beginner.

Last edited by Scrutinizer; 12-11-2012 at 06:26 AM.. Reason: Please select the segment before pressing the code button
# 2  
Old 12-11-2012
Try using sub(/.*\//,"",$11); before the print statement..
# 3  
Old 12-11-2012
OR..

Code:
awk '{n=split($11,P,"/");print $2 " " $5 ";" $7 ";" $9 ";" P[n]}'

This User Gave Thanks to pamu For This Post:
# 4  
Old 12-12-2012
Hello
1- Thanks alot.
2- Could you please explain what n and P are?
# 5  
Old 12-12-2012
Quote:
Originally Posted by frhling
Could you please explain what n and P are?
Here we are spiting that string into multiple fields.
n= Total number of fields.
P= This is an array which stores those fields from index as 1 to n.

Code:
$ echo "first-second-third" | awk '{n=split($0,P,"-");print n;for(i=1;i<=n;i++){print P[i],i}}'
3  # prints n here- it has 3 number of fields.
first 1
second 2
third 3

I hope this helps

pamu
This User Gave Thanks to pamu For This Post:
# 6  
Old 12-12-2012
try this to take c out of your pattern as required:
Code:
echo '/A/B/C' | sed 's/^\/.*\///'

# 7  
Old 12-12-2012
Really Thanks.
I dont know how to mark as :SOLVED but it is solvedSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

2. Shell Programming and Scripting

Need to remove slash

I got stuck in problem i need to remove slash but it is not working. current output /usr/sbin/httpd expected output usr sbin httpd (4 Replies)
Discussion started by: learnbash
4 Replies

3. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

4. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

5. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

6. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

7. UNIX for Advanced & Expert Users

Substitute single backward-slash with the double backward-slash

Hi, I have a path like this c:\test\sample\programs, i need to change thiis to c:\\test\\sample\\programs. How to perform this? I tried tr command but it didn't help me. Thanks Vijayan (3 Replies)
Discussion started by: mvictorvijayan
3 Replies

8. Shell Programming and Scripting

About \ (Back slash)

Hi All, print "path/executable_file parameters" \ > path/file1 print "path/executable_file parameters" \ > path/file2 print "path/executable_file parameters" \ > path/file3 chmod 775 path/file1 \ path/file2 \ ... (7 Replies)
Discussion started by: Arunprasad
7 Replies

9. Shell Programming and Scripting

Replace the last slash alone

Hi All, Can you please help me with the below issue. I want only the last slash to be replaced with space. 06/05/2008/EDED_FD_BDCD_ABCD_123 06/05/2008 EDED_FD_BDCD_ABCD_123 (3 Replies)
Discussion started by: christineida
3 Replies

10. Shell Programming and Scripting

awk slash

I have configuration file(master.cnf), that contents are: VER1LOG /src/ver1/log VER2LOG /src/ver2/log APPLOG /src/sys/apps/log APPCONF /src/sys/apps/conf APPBIN /src/sys/apps/bin my shell script is as below mylog=sys/apps awk "/$mylog/" master.cnf awk: syntax error Context is: >>> ... (6 Replies)
Discussion started by: McLan
6 Replies
Login or Register to Ask a Question