LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices



Reply
 
Search this Thread
Old 03-01-2010, 05:36 PM   #1
scripterJACK
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 0
gawk copy files (DOS pipes and redirects)


Hi I having great trouble with the insufficient features of DOS. I have a file 123ID.txt. I am supposed to parse the output of a command and redirect a specific string to a variable. The older DOS doesn't support 'for /f' option. So I went on to use gawk (DOS compatible) and my current script looks some thing like this:

<command> | gawk '$2=="ID:"{print $3}' > var

As you could see this redirects the third string in the line containing "ID:" as the second string, to var. After this I tried to assign var to a variable (myvar) as follows

type var | set myvar=

But this didn't help me either. Suppose var contains the string 123, my goal is to copy 123ID.txt to <somename>.txt. Can some one help me here?
 
Old 03-01-2010, 05:48 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,368
Blog Entries: 52

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
You can use the DOS prompt flag on the set to redirect from the file, ie:
Code:
set /p myvar=<var
(or just pipe this in directly from the gawk line)
 
Old 03-01-2010, 06:18 PM   #3
scripterJACK
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Original Poster
Rep: Reputation: 0
Hi neonsignal, thanks for the prompt reply, actually I tried both but surprisingly neither of them worked. I was trying to echo %myvar% but it doesn't give anything
 
Old 03-01-2010, 07:34 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Moved: This thread is more suitable in <GENERAL> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 03-01-2010, 07:51 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,241

Rep: Reputation: 194Reputation: 194
Code:
<command> | gawk '$2=="ID:"{print $3}' > var
echo set myvar= > __set.bat
copy __set.bat+var _set.bat
del __set.bat
_set.bat
del _set.bat
should work in theory.

Last edited by smeezekitty; 03-01-2010 at 07:53 PM.
 
Old 03-01-2010, 10:02 PM   #6
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,368
Blog Entries: 52

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
The '/p' option for set is a feature of the WinNT series command shell (cmd.exe). It was not in the earlier Win95 series shell (command.exe) or plain DOS. Of course, for more complex scripting, Windows now has the PowerShell which has a lot more features.
 
Old 03-02-2010, 12:53 PM   #7
scripterJACK
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Original Poster
Rep: Reputation: 0
Hi All,

Thank you everyone for taking time to respond to my issue and suggest solutions. I finally figured out two solutions.

1. This one requires strings.com from (you can search google for strings25.zip)
command > sid
strings var= read sid,3
strings sid= right %var%,4
del sid
echo %sid%
copy %sid%ID.txt ID.txt

2. command | gawk '$2=="ID"{print "set sid=" $3}' > id.bat
call id.bat
echo %sid%
del id.bat
copy %sid%ID.txt ID.txt

Honestly DOS shell sucks big time but unfortunately I have to live with it for a while
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In DOS fdisk, format, sys, copy files, edit autoexec - In linux? by hand? pentalive Linux - General 19 10-16-2013 09:53 AM
String copy in C using pipes. manavendra Programming 1 01-19-2010 07:45 AM
Using GAWK to combine files paragkalra Programming 4 11-14-2009 08:43 AM
examples with 2 pipes+fork+handling error,output in different files nagendrar Programming 4 11-06-2009 07:36 AM


All times are GMT -5. The time now is 04:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration