Computing.Net > Forums > Programming > awk/sed > env.variable from file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk/sed > env.variable from file

Reply to Message Icon

Name: drak
Date: January 4, 2006 at 07:58:41 Pacific
OS: Windows(any)
CPU/Ram: Enough
Comment:

Hello all

I'm trying to understand Pemente's awk/sed example #2 in using awk/sed to find a line in a text file and sending the content of that line into a variable. A search didn't really help me much...

http://www.student.northpark.edu/pemente/sed/bat_env.htm#sed

"
Example 2: Get John Doe's phone number from FOO.DAT, and put it into the variable %PHONE%

@echo off
:: Look for name John Doe, get field #4
awk "/John Doe/ {print \"set phone=\" $4}" FOO.DAT >tmp_.bat
call tmp_.bat
echo John Doe's phone number is /%PHONE%/
::
del tmp_.bat >NUL
set phone=
"


e.g.
Look for "Backup Path=[content]" in a text file, set %backup% to [content] using sed/awk.

I don't understand the "get field 4" part of Pemente's example: do we have to know the exact field/line number in the text file beforehand?

I'm using the win32 GNU port for SED, 3.02 (haven't gotten awk yet).

Thanks ahead of time.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 4, 2006 at 08:15:15 Pacific
Reply:

Are you using windows and a port of awk/sed?


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: FishMonger
Date: January 4, 2006 at 09:19:16 Pacific
Reply:

>> I'm using the win32 GNU port for SED, 3.02 (haven't gotten awk yet).

If you don't have awk then that's a very good reason why the awk command isn't working!!


0

Response Number 3
Name: drak
Date: January 4, 2006 at 09:45:37 Pacific
Reply:

No, I mean I haven't tried to write a batch for this yet because I don't understand what that particular line means. :P
I'd like to figure out what the commands are before writing the actual batch. Ah, nevermind...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: awk/sed > env.variable from file

awk: search string across 2 files www.computing.net/answers/programming/awk-search-string-across-2-files/10872.html

getting a variable from batch file www.computing.net/answers/programming/getting-a-variable-from-batch-file/16771.html

Variable from a list file www.computing.net/answers/programming/variable-from-a-list-file/17057.html