![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UNIX newbie NEWBIE question! | Hanamachi | UNIX for Dummies Questions & Answers | 4 | 03-28-2009 04:10 PM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 01:25 PM |
| Taking Aim | iBot | Complex Event Processing RSS News | 0 | 11-14-2007 08:10 AM |
| quick newbie bash question | redsand9009 | Shell Programming and Scripting | 4 | 01-25-2007 03:44 AM |
| Newbie - Need help in bash scripting | coolbib | Shell Programming and Scripting | 4 | 08-11-2002 09:28 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
A few questions: I'm trying to use Bash (although I'm not against using AWK) to try to accomplish a few things, but I'm stumped on a few points.
I'm learning most of the basics quickly: but there are a few things I can't figure out. 1. I'm trying to count the number of .txt files in a directory and save it in a variable. I can use find $DIRECTORY -name *.txt | wc -l but can't save that in a variable. ![]() 2&3. Is it possible to actually open these files (this will be a separate task entirely) and read a specific line? All of them are formatted the same, and I need to be able to read that line and save THAT to a list/array of variables- there are over 10,000 files- and I need the fourth line in each .txt. Many of these .txt files should have this line the same, so the array will never approach 10,000 - but I do need to be able to count how many times each appears- how would I do this? ![]() (I know how to use loops, and create variables, but not open files (and read specific lines) nor make arrays/lists/whatever you call them in bash. <-Used to Java/Python; but can't use either here. ![]() Any help with this is greatly appreciated- and I thank you for any help you can provide. ![]() Last bit: the files are all named similarly... 309456_20.txt 503256_01.txt etc. and all the files are in subdirectories named the same as the first three digits of the file. So 309456_20.txt would be in subdirectory 309. I'm not looking for a fast program or even a relatively efficient one; as long as it gets the job done. Last edited by Asylus; 12-17-2007 at 01:44 PM.. Reason: Additional Information |
|
||||
|
For part 1 ...
TESTVAR=$(find . -name log_20070911* |wc -l) echo $TESTVAR 1 If you enclose a command in $( ) then the output of that command is used, in this case, assigned to the variable TESTVAR. You could use ` ` also. Martin (Parts 2/3 I need to think about) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|