![]() |
|
|
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 |
| Need to solve complex network problem | soliberus | IP Networking | 4 | 02-24-2008 10:30 AM |
| Complex problem about nested for loops | Silverlining | Shell Programming and Scripting | 4 | 10-18-2007 05:19 PM |
| problem with count | uni_ajay_r | Shell Programming and Scripting | 5 | 11-06-2006 08:14 AM |
| How to count the record count in an EBCDIC file. | oracle8 | UNIX for Dummies Questions & Answers | 1 | 07-26-2006 08:22 PM |
| Complex Pipeline/Redirection/Regular Expression problem | netmaster | UNIX for Dummies Questions & Answers | 1 | 11-29-2005 12:55 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Complex file count problem
Hi all!
I have a question regarding possibilities to do line counts. SEARCH_VAR=TEX rsh $REM_HOST -l $REM_USER "cd $REM_DIR; ls *$SEARCH_VAR* 2> /dev/null" | sort -n | awk 'BEGIN { FS = "-" } ; { print $1"\t"$0 }' Will produce an output on the screen like this: 483 483-SOME-TEXT-1 643 643-SOME-TEXT-2 692 692-SOME-TEXT-3 723 723-SOME-TEXT-4 For the files I'm searching for. This is exactly what I want I also what I get at the moment. But if I search for something and no files are found it would be nice to have a message like 'No files match the search criteria'. I need both the output on the screen and the file count. I guess I could do it like this: First this to get the desired output on the screen: rsh $REM_HOST -l $REM_USER "cd $REM_DIR; ls *$SEARCH_VAR* 2> /dev/null" | sort -n | awk 'BEGIN { FS = "-" } ; { print $1"\t"$0 }' Then this to get the count of the files: LINECOUNT=$(rsh $REM_HOST -l $REM_USER "cd $REM_DIR; ls *$SEARCH_VAR* 2> /dev/null | wc -l") But that I don't like for two reasons. I have to do two remote shell sessions and also the code gets ugly... Doing like this will get the file count printed on the screen but I need it in a variable that I can use to compare with later. rsh $REM_HOST -l $REM_USER "cd $REM_DIR; ls *$SEARCH_VAR* 2> /dev/null" | sort -n | awk 'BEGIN { FS = "-" } ; { print $1"\t"$0 filecount++ } ; END { print filecount }' Like: if [[ $FILECOUNT = "0" ]]; then Hopefully all in one go... Is this at all possible...? Using awk somehow? Assign the "filecount" in the awk script to a variable?Oh, this is in Korn shell. Thanks for any help! |
|
||||
|
Quote:
Code:
> /tmp/file_count.$$ Code:
lines=`cat /tmp/file_count.$$ | wc -l` if [ $lines -eq 0 ]; then echo "mo match" else cat /tmp/file_count.$$ echo "$lines matches found" fi rm /tmp/file_count.$$ |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|