![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| awk continue | anhtt | Shell Programming and Scripting | 3 | 03-11-2008 12:08 PM |
| Continue Script when File Found | Jose Miguel | Shell Programming and Scripting | 7 | 11-07-2006 08:43 PM |
| Continue an 'scp' tranfser? | deckard | UNIX for Advanced & Expert Users | 3 | 12-19-2005 05:08 PM |
| Will the continue function work ???? | kamlesh_p | Shell Programming and Scripting | 2 | 10-12-2005 09:27 AM |
| continue the suspended jobs | killerserv | UNIX for Advanced & Expert Users | 6 | 01-10-2002 03:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
continue example
The following code for search a pattern in file name (or entire file name) and look at its size, code is derived from an ebook about scripting. It is working in HP Unix but I am unable to run in Linux (Ubuntu) Please advise me what is wrong for Linux?
And besides , how can I get rid of errors in case of the file is not available? Code:
pattern=core
total=0
for f in *
do
[ ! -f $f ] && continue
if grep $f $pattern > /dev/null
then
size=`cat $f|wc -c`
total=èxpr $total + $size`
fi
done
echo Total size of $pattern is $total
|
|
||||
|
You are hundred percent right about grep, how I did mistake is my test file consist of file name what a bad coincidence. I wondered that how my code didn't work today, whereas it was working yesterday
![]() Thanks a million, I hope, I will learn more in time |
|
|||||
|
Xramm,
According to what you said, you are looking for: 1) Search for a pattern into a file name. 2) At the end, display the total size of all files with pattern in their name. Based on your specification, here is one solution not having to read the entire file to find how many characters it has -- very useful for large files. Code:
typeset -i mSize
typeset -i mTotal=0
mPattern='core'
for mFile in `find . -type f -name "*${mPattern}*"`
do
mSize=`ls -l $mFile | tr -s ' ' | cut -d' ' -f5`
mTotal=${mTotal}+${mSize}
done
echo 'Total size of '$pattern' is '${mTotal}
|
![]() |
| Bookmarks |
| Tags |
| linux, ubuntu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|