The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 05:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 01:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 06:44 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-29-2008
Registered User
 

Join Date: Jul 2008
Posts: 6
Lightbulb awk command help

Hi,

I am storing ~ seperated string in a variable and by using awk i am storing values into different variables.

One of the value is windows directory structure.

like -> C:\Program files\my doucment\work\dev\test

Again I want to retrieve 'test' from this string into a variable.

v_output="C:\Program files\my doucment\test"
v_test=`echo $v_output | awk -F"\" '{print $5}'|sed 's/ //g' `

this command give me null value.

can someone help me with correct awk command?
Reply With Quote
Forum Sponsor
  #2  
Old 07-29-2008
Registered User
 

Join Date: Jul 2008
Posts: 6
It seems that awk is not able to read "\" becuase when i replace \ with any other character like "t". it is giving me result.

is this issue in Unix? escape char.
Reply With Quote
  #3  
Old 07-29-2008
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Quote:
Originally Posted by aindurkhya View Post
Hi,

I am storing ~ seperated string in a variable and by using awk i am storing values into different variables.

One of the value is windows directory structure.

like -> C:\Program files\my doucment\work\dev\test

Again I want to retrieve 'test' from this string into a variable.

Quote:
v_output="C:\Program files\my doucment\test"
v_test=`echo $v_output | awk -F"\" '{print $5}'|sed 's/ //g' `

this command give me null value.

can someone help me with correct awk command?
The catch here is "\test" being interpreted as tab "\t" when echoed,But was able to work round
Code:
v_test=`echo -E $v_output | awk -F"\" ' { print $6 }'`
May be if your unix flavor has that "-E" option for echo,its quite straight forward.

Thanks
Nagarajan G
Reply With Quote
  #4  
Old 07-29-2008
Registered User
 

Join Date: Jul 2008
Posts: 6
Thumbs up

hey thanks for reply but i got the solution.

in place of seraching "\" i search for "\\\" which has resolved the isuse.
Reply With Quote
  #5  
Old 07-29-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
Another way:
Code:
v_output="C:\Program files\my document\test"

v_test=`echo $v_output | sed 's/.*\\//'`
Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0