looking for files and modify if size matches


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting looking for files and modify if size matches
# 1  
Old 02-15-2008
looking for files and modify if size matches

hi there.

I'm at SunOS 5.9

At my new job i'm using UNIX, and it's my first time.

i'm trying to make a script for:

-find files with a name passed to it as parameter
-compare results with file size passed as parameter too
-when comparison's true --> move file
-if not--> make nothing

well, i'll have prevent too similer name-size files. but i can solve that later.


my trouble now is in spliting string with awk. i can't understand why it doesn't

work


name=`find $CLL_DAT -name "$1*" -print`;
lines=`awk 'END { print NR }' $name`
echo "$lines";
if [ "$lines" = "$2" ];
then
echo "here i'll do what i have";
else
echo "ERROR $name";
fi


this is working, but i need to expand string catched by find, into 'n' strings,

and make things for all of them.


name=`find $CLL_DAT -name "$1*" -print`;
awk '{n=split($name,names," ")}'#########################i don't know how to make work this split function
flag=0

for (( i = 0 ; i <= n; i++ ))
do
lines=`awk '{END { print NR }}' ${names[$i]}`
echo "$lines"
if [ "$lines" = "$2" ];
then
if ["$flag" = 1];
then
echo 'two files matches'
exit
fi

flag=1
name=${names[$i]}
echo 'matches'
else
echo "don't matches"
fi
done
# 2  
Old 02-15-2008
Code:
find $CLL_DAT -name "$1*" -print | \
while read name
  lines=`awk 'END { print NR }' $name`
  echo "$lines";
  if [ "$lines" = "$2" ];
  then
    echo "here i'll do what i have";
  else
    echo "ERROR $name";
  fi
done

# 3  
Old 02-17-2008
thanks sb008, it really works!
thanks a lot


but i can't catch what really means | \

can you explain me briefly?
Smilie
# 4  
Old 02-18-2008
Quote:
Originally Posted by viko
thanks sb008, it really works!
thanks a lot


but i can't catch what really means | \

can you explain me briefly?
Smilie

The "\" means that the line continues on the next line.

Actually it is:

find $CLL_DAT -name "$1*" -print | while read name

but for readability I start the while loop on the next line

similar:

ls | grep <something> | sort

could be written as

ls | \
grep <something> | \
sort


Same can be done with conditions

if [ <condition1> -o <condition2> -o <condition3> ]

if [ <condition1> -o \
<condition2> -o \
<condition3> ]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 files and print matches and non-matches in separate files

Hi all, I have two files, chap.txt and complex.txt. chap.txt looks like this: a d l m r k complex.txt looks like this: a c d e l m n j a d l p q r c p r m ......... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

2. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

3. Solaris

Modify pset size

I 'm unable to modify pset size configuration. # poolcfg -c 'modify pset pset-app (uint pset.size = 16 )' poolcfg: put property pset.size failed: Bad parameter supplied (2 Replies)
Discussion started by: fugitive
2 Replies

4. Shell Programming and Scripting

how to modify ramdisk size,kinda urgent !!!

Hi all, I wanted to know how to modify the size of the ramdisk? I mean am manipulating a live cd ,for which the file am manipulating is within a ramdisk now due to size constraints i am unable to play around with some stuff.... currently the size of the ram disk is 64M... I would like to... (1 Reply)
Discussion started by: wrapster
1 Replies

5. UNIX for Advanced & Expert Users

how to modify font size and type from script

I need to print different lines in different font types and sizes to the terminal window from csh script. I can easily change font color and print characters in bold or underline, but cannot figure out a way to change font. Any help is greatly appreciated.:confused: (3 Replies)
Discussion started by: helido
3 Replies

6. UNIX for Advanced & Expert Users

Command similar to "touch" for modify File size

Hi All, I'm trying to find a command like similar to "touch" which would let me change the file size property. For ex: I have a file of size 1MB using the command i would like to set/update the size something like 1KB. Is it possible? Is there any such command which would accomplish this... (3 Replies)
Discussion started by: sriharshareddyk
3 Replies

7. Shell Programming and Scripting

Looking for a string in files and reporting matches

Can someone please help me figure out what the command syntax I need to use is? Here is what I am wanting to do. I have hundreds of thousands of files I need to look for a specific search string in. These files are spread across multiple subdirectories from one main directory. I would like... (4 Replies)
Discussion started by: btrotter
4 Replies

8. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies

9. Solaris

Modify the size of parttion under solaris

:( Hello! is there a tool like partition magic under solaris 9 to modify the size of the partitions. I do not manage to install patches because I do not have any more a place in the partition root. Thank you (1 Reply)
Discussion started by: toufik
1 Replies

10. UNIX for Dummies Questions & Answers

Comparing two files and noting matches

I have two files. One contains names and another file (66 MB, ASCII format) contains details of persons. How do I compare the names in the first file with the second file and write the matches to a third file. I would prefer this to be solved in UNIX or VB. Thanks. (2 Replies)
Discussion started by: augustinep
2 Replies
Login or Register to Ask a Question