The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
while loops nymus7 Shell Programming and Scripting 4 03-31-2006 09:59 AM
two loops big123456 UNIX for Dummies Questions & Answers 2 10-11-2005 12:08 AM
While Loops vdc UNIX for Dummies Questions & Answers 4 05-10-2005 05:55 AM
Loops mariner UNIX for Advanced & Expert Users 2 07-01-2004 04:50 AM
loops? jonas27 UNIX for Dummies Questions & Answers 1 11-05-2001 11:28 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-26-2005
Registered User
 

Join Date: Jun 2003
Posts: 20
While loops and awk

I am trying to make a script that will replace backslashes in a file, but only if the occurance is a pathname. In the file, there are a lot of regular expressions as well, so I'm trying to preserve the integrity of those regular expressions, but convert Windows relative paths. I'm using bash and this is what I've tried:

line="~/path/to/something~ ~\path\to\something~"
loop=2
while [ ! "`echo \"$oldline\" | grep '\\\'`" ]; do # see note...
oldline="`echo \"$line\" | tr -d '\r' | awk -F \~ '{print $loop}'`"
let loop=$loop+2
done

Note: I'm using Mac OS X and apparently Darwin doesn't like a simple escaped backslash. I have to escape the escaping backslash to get it to work. Just don't try to match multiple backslashes, 'cause then it's even more crazy. Just a side note...

I've tried these variants of the $loop variable in the awk statement:
awk -F \~ '{print $loop}'
awk -F \~ '{print $$loop}'
awk -F \~ '{print \$$loop}'
awk -F \~ '{print $\$loop}'
awk -F \~ '{print $"$loop"}'

Of course, they all lead to the same error - illegal field $loop. Can anyone help me with an alternate way of doing this?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-26-2005
Registered User
 

Join Date: Jun 2003
Posts: 20
After a little bit of fiddling around, I figured out a solution:

awk -F \~ '{print $'$loop'}'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:34 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 Global Fact Book

Content Relevant URLs by vBSEO 3.2.0