![]() ![]() Using $(.) instead of back-quotes is generally a good idea. However, you don't need eval again: for d in $(ls $AWSTATSCONF/awstat*conf | egrep -v "$f") That is, the while loop is processed by a sub-shell, not the main shell, so if you are relying on the loop to set variables in the main shell, it won't work - and you can/should go back to the for loop. Be wary of subprocesses not being able to affect the parent shell's variables. ![]() The while read formulation is another way of writing the for loop. I assume you don't have any stats files with names containing 'antidisestablishmentarianism' lurking around (yes, it's a real word it is mostly used here as a joke, though). You'd probably want to look at building an egrep (or grep -E) command: f="antidisestablishmentarianism" It probably won't be too serious for demonstration purposes, but if you're dealing with production work and thousands of files.not so good. The chosen mechanism of running 20 greps in sequence if there are 20 terms to exclude uses a lot of processes. Beware: eval is a powerful and therefore dangerous tool. Using eval like that forces the shell to treat the pipes in the string $f as pipes in the shell. In a Windows PowerShell the alternative for grep is the Select-String command. The findstr command is a Windows grep equivalent in a Windows command-line prompt (CMD). , -, and _).Īssuming that you only have to deal with portable filenames, then you could get the effect you wanted with: for i in $EXCLUDEįor d in `eval ls $AWSTATSCONF/awstats*conf $f` The grep command in Linux is widely used for parsing files and searching for useful data in the outputs of different commands. How justified those are depends on whether you have to deal with all possible file names (ones containing spaces and newlines are particularly problematic), or whether you have normal file names that use just the portable filename character set (which, according to POSIX, are the (Latin) alphabet, the digits, plus. There are, rightly, misgivings about parsing the output of ls. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |