Friday, May 21, 2010

Please solve my unix shell scripting question?

1.is there any command in Unix through which i can get weather a string is present or not in a file first line(not hole file contents only first line) ?.


2. I have a file which consist name of files.i want to print every file contents and at end of each file message which print "smal file " if lines are less then 50 else "big file" .


please give me some idea.i am trying to do it with cat and wc -l command .but.....

Please solve my unix shell scripting question?
1. A basic concept of Unix shell scripting is to divide and conquer. You've probably seen people run stuff like:





command1 | command2 | command3 ...





So, if you can divide up the tasks, you can perhaps use two commands to meet your needs if one command doesn't do everything. If you are writing the above commands, perhaps "command2" is something where you can shove in a stock standard program that comes with Unix to do some specific job (sort, awk, sed, etc.).





In this case, you want to use "head" to get the first line, and then use "grep" to see if the string is there (if the output is 0 bytes, it was not there).





2. I'm wondering if a "find" command would work. Can you find all files less than 50, and print their names along with "small file", then turn around and find any files bigger than 50 and print "large"?





This is also probably do-able with awk.
Reply:1. grep -r "string" * {for example grep -r "finename"* }





2. Do ls -atl ...this will give the details of all the contents ..so with the size of the bytes u will know which file is ssmall and which is big.


No comments:

Post a Comment