![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Minicom runscript: How to send escape character ( \ ) | rkhanna | Shell Programming and Scripting | 1 | 10-02-2008 10:14 AM |
| read a variable character by character, substitute characters with something else | vipervenom25 | UNIX for Dummies Questions & Answers | 2 | 06-06-2008 03:18 PM |
| Escape character | deepakpv | Shell Programming and Scripting | 4 | 02-16-2007 03:19 AM |
| Escape character in vi? | stevefox | Shell Programming and Scripting | 4 | 11-17-2005 03:38 PM |
| possible to escape the \ character in sed? | gammaman | UNIX for Dummies Questions & Answers | 1 | 07-07-2005 02:49 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk / escape character
Hi
I'm trying to split a dir listing eg /home/foo1/foo2 I'm using ksh I've tried dir=/home/foo1/foo2 splitit=`echo $dir | awk -F '\/' '{print $1}'` echo $splitit nothing is output! I have checked the escape character. The only one I have found is \ BTW `pwd` | awk -F \/ '{print $1}' works from cmdline Why is this not working? I want to split the string and then put it into an array, get the size of it and then get the right most directory Last edited by OFFSIHR; 11-29-2006 at 12:08 PM.. |
|
||||
|
Quote:
I have used basename foo2 and it returns foo2 I did not see the NF on the end - now I get 6 (yes 6!) returned to this script dir=/home/foo1/foo2 splitit=`echo $dir | awk -F '/' '{print $NF}'` echo $splitit when i use the script below blank is returned dir=/home/foo1/foo2 splitit=`echo $dir | awk -F '/' '{print $1}'` echo $splitit desired output is foo2. last folder name is only known when the script is run (its run from another script) thanks |
|
|||||
|
Quote:
Quote:
you're outputting '$1' - FIRST field. You have an ABSOLUTE path with the LEADING '/'. What would be the FIRST field in a string '/a/b/c/d'? It would be the string BEFORE the FIRST fieldSeparator. What is it in this case? It's the 'blank' character. field1 -> 'blank' field2 -> a field3 -> b field4 -> c field5 -> d Quote:
|
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|