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 !!

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-17-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
awk question

Is there a string concatenation function such as the 'C' strcat in awk? If not, how could I accomplish this (using awk)?
Reply With Quote
Forum Sponsor
  #2  
Old 12-17-2003
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Re: awk question

Quote:
Originally posted by google
Is there a string concatenation function such as the 'C' strcat in awk? If not, how could I accomplish this (using awk)?
i know you said awk. but here is my .02 in perl you can use the "." to concatiniate.

according to this site:

http://www.cs.uu.nl/docs/vakken/st/nawk/nawk_60.html

There is only one string operation: concatenation. It does not have a specific operator to represent it. Instead, concatenation is performed by writing expressions next to one another, with no operator. For example:
Reply With Quote
  #3  
Old 12-17-2003
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
There is no separate strcat function in awk. String
concatenation is build into the language.

Here is a simple awk script which demonstrates
string concatenation in awk.

BEGIN {
str="strcat"

for (i =0; i < 3; i++)
str = str " demo" i

print length(str), str
}

Hope this helps
- Finnbarr
Reply With Quote
  #4  
Old 12-17-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Code:
echo $PARENT_PATH | awk ' {
     
              arraySize = split($0, parentPath, "/");
              delete parentPath[arraySize];
    
              for (i in parentPath ) {
               w = w parentPath[i];
  
              }
              print w
            }'
I need a quick way to strip the last node of a directory path, given a directory path as input. The code above falls short in that the output does not include the "/" in the path. I need a way to append the "/" between each node. I have tried to do the following:
r = /
w = w r

but awk doesnt like it!

thanks for the help.

Last edited by google; 12-17-2003 at 04:17 PM.
Reply With Quote
  #5  
Old 12-17-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Code:
echo $PARENT_PATH | awk ' {
     
              arraySize = split($0, parentPath, "/");
              delete parentPath[arraySize];
    
              for (i in parentPath ) {
               w = w "/" parentPath[i];
  
              }
              print w
            }'
Works. Cool. Thanks for all of your help.
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 08:52 AM.


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