Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Moving files
I'm struggling with batch files moving.

I have several files named "file  001.jpg"   #contains two blank spaces
or "file 002.jpg"                            #contains one blank space

I would like to know how to move them using system() in awk.

I can print them:

ls | awk '{print $1"_"$2}'

but how to move them from source to target file?

Svata

Report this thread to moderator Post Follow-up to this message
Old Post
Svatoboj
10-04-04 01:38 AM


Re: Moving files
ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<2s8mq4F1hrf51U1@uni-berlin.de>
..
>
> And of course in this newsgroup, you made the right choice. You could
> do it all using a Bourne-compatible shell, like this
>
>  for a in *
>  do
>     set -- $a
>     mv "$a" $1_$2
>  done

Well, there are several approaches to same task. Awk is handy as its
syntax is really space saving.
Sorry, if I date too much, but can you tell me what  "set -- $a"
exactly does?

Svata

Report this thread to moderator Post Follow-up to this message
Old Post
Svatoboj
10-04-04 01:55 PM


Re: Moving files

Svatoboj wrote:
> ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<2s8mq4F1hrf51
U1@uni-berlin.de>...
> 
>
>
> Well, there are several approaches to same task. Awk is handy as its
> syntax is really space saving.
> Sorry, if I date too much, but can you tell me what  "set -- $a"
> exactly does?

sets the postional parameters $1, etc. to be whatever space-separated
values are stored in $a. For more details, look up the "set" command in
your shells man page (e.g. http://www.rt.com/man/ksh.1.html for ksh).

Ed.

> Svata

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
10-04-04 01:55 PM


Re: Moving files
Ed Morton <morton@lsupcaemnt.com> wrote in message news:<4OednV5VH8aa2_zcRVn-hA@comcast.com
>...
>

> sets the postional parameters $1, etc. to be whatever space-separated
> values are stored in $a. For more details, look up the "set" command in
> your shells man page (e.g. http://www.rt.com/man/ksh.1.html for ksh).

Thank you for your reply. I looked up "set" command in BASH manual
page, but I still don't understand how it works.
>
> 	Ed.
>
Svata

Report this thread to moderator Post Follow-up to this message
Old Post
Svatoboj
10-05-04 01:55 PM


Re: Moving files
On 2004-10-05, Svatoboj wrote:
> Ed Morton <morton@lsupcaemnt.com> wrote in message news:<4OednV5VH8aa2_zcR
Vn-hA@comcast.com>... 
> 
>
> Thank you for your reply. I looked up "set" command in BASH manual
> page, but I still don't understand how it works.

What don't you understand?

There are three functions to set (taken from the bash man page):

1.  Without options, the name and value of each shell variable
are displayed in a format that can be reused as input.

2.  When options are specified, they set or unset shell
attributes. E.g., set -f, set -x, set +v

3.  Any arguments remaining after the options are processed are
treated as values for the positional parameters and are
assigned, in order, to $1, $2, ...  $n.

--
Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License

Report this thread to moderator Post Follow-up to this message
Old Post
Chris F.A. Johnson
10-05-04 01:55 PM


Re: Moving files
In article <61792dff.0410050132.7b5a68b8@posting.google.com>,
Svatoboj <svatoboj@centrum.cz> wrote:

% Thank you for your reply. I looked up "set" command in BASH manual
% page, but I still don't understand how it works.

Set allows you to restate the shell's command line. You can set
shell options and replace positional parameters. If you write

set $whatever

the shell expands the shell variable `whatever', then divides it up
using the value of IFS or white space if IFS is not set, and assigns
each piece to a positional parameter. For instance

whatever="a b c"
set $whatever
echo $2

will print `b'. This doesn't work correctly if $whatever has no
value or it begins with - or +. I used -- to say that the rest
of the command line should be assigned to positional parameters.

whatever="-a b c"
set $whatever
echo $2 # prints c
set -- $whatever
echo $2 # prints b
--

Patrick TJ McPhee
East York  Canada
ptjm@interlog.com

Report this thread to moderator Post Follow-up to this message
Old Post
Patrick TJ McPhee
10-06-04 08:56 AM


Re: Moving files
ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<2s8mq4F1hrf51U1@uni-berlin.de>
..
>
> And of course in this newsgroup, you made the right choice. You could
> do it all using a Bourne-compatible shell, like this
>
>  for a in *
>  do
>     set -- $a
>     mv "$a" $1_$2
>  done

Well, there are several approaches to same task. Awk is handy as its
syntax is really space saving.
Sorry, if I date too much, but can you tell me what  "set -- $a"
exactly does?

Svata

Report this thread to moderator Post Follow-up to this message
Old Post
Svatoboj
10-07-04 08:55 AM


Re: Moving files

Svatoboj wrote:
> ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<2s8mq4F1hrf51
U1@uni-berlin.de>...
> 
>
>
> Well, there are several approaches to same task. Awk is handy as its
> syntax is really space saving.
> Sorry, if I date too much, but can you tell me what  "set -- $a"
> exactly does?

sets the postional parameters $1, etc. to be whatever space-separated
values are stored in $a. For more details, look up the "set" command in
your shells man page (e.g. http://www.rt.com/man/ksh.1.html for ksh).

Ed.

> Svata

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
10-07-04 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:51 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.