- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 07:46 AM
05-02-2007 07:46 AM
I am doing a " ls -ltr |grep -v "*.gz" " - so that I cant view gzipped files but they still show up . How to get a listing without the gzipped file.
thanks
hunki
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 07:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 07:55 AM
05-02-2007 07:55 AM
Re: grep problem
# ls -ltr |grep -v -F .gz
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 07:58 AM
05-02-2007 07:58 AM
Re: grep problem
ls -ltr |grep -v *.gz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 08:40 AM
05-02-2007 08:40 AM
Re: grep problem
I have reached a point where I get the following output , what I need to know is how to pass the 0502 as a value to a variable.
## ls -ltr |grep -v -F .gz |awk '{print $9}' |awk -F"." '{print $3}'
0502
0502
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 08:43 AM
05-02-2007 08:43 AM
Re: grep problem
# VAR=$(ls -ltr |grep -v -F .gz |awk '{print $9}' |awk -F"." '{print $3}')
pass VAR to your script named "myscript" as follows:
# ./myscript $VAR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 08:45 AM
05-02-2007 08:45 AM
Re: grep problem
echo $VAR
0502 0502
I just want one - 0502 passed as Variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 08:49 AM
05-02-2007 08:49 AM
Re: grep problem
# VAR=$(ls -ltr |grep -v -F .gz |awk '{print $9}' |awk -F"." '{print $3}' | sort -u)
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 08:55 AM
05-02-2007 08:55 AM
Re: grep problem
Two awk's is likely resulting in double output.
VAR=$(ls -ltr |grep -v -F .gz |awk '{print $9}' |awk -F"." '{print $3}')
Try it with 1.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 09:13 AM
05-02-2007 09:13 AM
Re: grep problem
I think you can optimize something like this:
# ls -ltr |awk '$NF!~/.gz/ {n=split($NF,a,/\./);if (n==3) {print a[2]}}'
Hence if you had a file named "/tmp/myfile.123.log" you would be returned "123".
Anytime you 'grep' and pipe to 'awk' you are adding an extra process that 'awk' can accomodate!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 09:43 AM
05-02-2007 09:43 AM
Re: grep problem
One more problem :
When I am doing a "mv filename.$VAR filename" it says
mv: filename not found
where VAR is the 0502.
there is a file by the name filename.0502 that exists in the directory but mv does not work when I supply the variable. Also when I do a echo $VAR , I do get the 0502 value for it.
Please suggest whats the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 09:54 AM
05-02-2007 09:54 AM
Re: grep problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 09:57 AM
05-02-2007 09:57 AM
Re: grep problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 10:03 AM
05-02-2007 10:03 AM
Re: grep problem
# ls -1 *05* | cat -ve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 10:05 AM
05-02-2007 10:05 AM
Re: grep problem
filename.rar.0502$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 10:08 AM
05-02-2007 10:08 AM
Re: grep problem
~thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 10:13 AM
05-02-2007 10:13 AM
Re: grep problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 10:53 AM
05-02-2007 10:53 AM
Re: grep problem
You need to source (read) your profile by doing:
. $HOME/.profile
In this fashion, you will propagate any environmental variables form your profile into your script.
By the way, when using 'cat -ev' the "$" character is a newline character.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 05:56 PM
05-02-2007 05:56 PM
Re: grep problem
$ ls -ltr !(*.gz)
>Sandman: Piping to sort for uniqueness should do the trick for you:
It seems this is correct. There seems to be N files that have X.y.date, there X varies. So the initial script will return the same one twice.
>JRF: You need to source (read) your profile by doing:
While this is true, why would you ever need to source your .profile except if you are in a remsh or crontab script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2007 12:44 AM
05-03-2007 12:44 AM
Re: grep problem
But my original problem got left out ...
mv: filename not found
how to sort that out , please suggest.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2007 01:39 AM
05-03-2007 01:39 AM
Re: grep problem
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2007 02:29 AM
05-03-2007 02:29 AM
Re: grep problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2007 03:02 AM
05-03-2007 03:02 AM
Re: grep problem
>$ ls -ltr !(*.gz)
above works only if the current directory didn't have any subdirs underneath and reduce overhead of a long pipeline by removing dups in the first awk construct...
# ls -ltr | grep -v -F .gz | awk '{n=split($9,z,".")}END{print z[n]}'
~cheers