1834915 Members
2576 Online
110071 Solutions
New Discussion

Re: unix script problem

 
Nitin Nigam
Occasional Advisor

unix script problem

Hi,
I have written the scrip and using the below command:
ls -1 | awk '{print $NF}' | cut -f1 -d'.' | grep -v '_[0-9]' | sort -u

this gets all the files till the period and than ignores them if they have " _[0-9] " its working ok but I find out that its not getting only one file with the name "nwit00_1400.Oct21"
because this file got " 00 " before " _1400"

what I think is above command first gets the filename till period so it will be "nwit00_1400" than ignores the files with "_1400" (underscore and nubmers) but its ignoring this file altogether can someone help me, what should I do so I can get all the files including this one.

thanks
2 REPLIES 2
T G Manikandan
Honored Contributor

Re: unix script problem

Please revert with the list of files too and what you need
curt larson_1
Honored Contributor

Re: unix script problem

actually the grep will match lines not contain an underscore followed by a digit.
but it doing just what it is supposed to do.
just an ls would do the same as ls -1 for you. and with only one filename per line, using awk to print the only field is unnecessary.
ls | cut -f1 -d'.' | grep -v '_[0-9]' | sort -u
would do just the same for you. and
ls | awk -F'.' { if ( $1 !~ /_[0-9]/ ) print $1;}' | sort -u
is a bit faster

hard to give advice on how to help you without knowing what's your data and what your expected output should be