Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > What does this mean?
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 10th November 02:13
External User
 
Posts: 1
Default What does this mean?



This is in a script I inherited from someone. Can someone tell me what
the hek its doing to the file $myFile?

I can tell its altering the file but I don't know what exactly its
doing to it.

awk '/^.E.\(/{print "1"};!/^.E.\(/{printf " %s\n",$0}' ${myFile} >
${RPT_TO}/${myFile}


Thanks!
  Reply With Quote


 


2 10th November 02:13
chris f.a. johnson
External User
 
Posts: 1
Default What does this mean?



It is not doing anything to $myFile; it is reading the file,
modifying its contents and storing it in ${RPT_TO}/${myFile}.

To understand the script, format it so that its structure is clear
(the time saved in typing the scrunched form is lost many times
over when trying to understand or modify it):

awk '
/^.E.\(/ { print "1" }
!/^.E.\(/ { printf " %s\n", $0 }
' ${myFile} >${RPT_TO}/${myFile}


The script prints "1" if the second and fourth characters in the
line are 'E' and '(' respectively, and prints the line itself if
they are not. --
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
  Reply With Quote
3 10th November 02:14
External User
 
Posts: 1
Default What does this mean?


Thank you for your insight on formatting the awk command and your
translation.

Can you break it down just a little more?
Is it actually replacing the whole line with 1 if the 2nd and 4th
characters are 'E'?

And I don't quite understand what its doing if the 2nd and 4th
characters are not E.

Additionally - how do you know it is looking for the 2nd and 4th
characters. this is very strange syntax!

Typically in a programming language you'd see something more like:

//made up non-language specific pseudo code here:
ch1 = somestring.charAt(1);
ch2 = somestring.charAt(3);

if(ch1.eq('E') && ch2.eq('E"){
//do something
}


Does it replace the whole line with '('
  Reply With Quote
4 10th November 02:14
chris f.a. johnson
External User
 
Posts: 1
Default What does this mean?


[please do not top post]

It's not testing whether the 2nd and 4th characters are E; it is
checking whether the 2nd character is E and the 4th character is
(.

Try it and see:

printf "WER(TY)" "QWERTY" |
awk '
/^.E.\(/ { print "1" }
!/^.E.\(/ { printf " %s\n", $0 } '

It prints the line ($0) preceded by a space:

printf " %s\n", $0

It's a "regular expression". If you are going to use awk, you
need at least a basic understanding of how they work.

The awk man page has the basics, and the book, "The AWK
Programming Language", is a good introduction. You can also find
links to web pages on awk and regular expressions on my shell
page: <http://cfaj.freeshell.org/shell>.


Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666