LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-23-2016, 04:27 PM   #1
wrmosca
LQ Newbie
 
Registered: Mar 2015
Posts: 5

Rep: Reputation: 0
Alias command using awk


I have a log file that lists errors and is very cumbersome to go through. I'm only interested in a line if the 3rd column is a 2 or a 3. The command I use is:
cat cconsole.log | awk '{ if($3==2 || $3==3) print}'

This works very well but is awkward to type all the time. I'd like to create an alias in my .bashrc file but it isn't working. My guess is that the single quotes is breaking it. Using the alias returns nothing. Running the command returns what I expect.

How can I write this so it will work as an alias?
 
Old 09-23-2016, 04:46 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Hi, it's the unescaped $ character that may be your issue
You could shorten your awk expression also
Code:
alias catcconsole="awk '\$3==2 || \$3==3' cconsole.log"
But I would give full path to cconsole.log
 
Old 09-23-2016, 06:09 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
grail will be along soon to shorten it even more ...
 
Old 09-24-2016, 11:15 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I see my reputation precedes me ... but alas, keefaz has produced the good oil

My only additional suggestion would be to make a function so you could pass an alternative file name if needed.

Last edited by grail; 09-24-2016 at 11:16 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 12:46 AM
bash: command works at command line, but not via an alias porphyry5 Programming 3 03-17-2012 02:48 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
tar command alias command rlg Linux - Newbie 0 03-11-2008 07:21 AM
alias command zeviddalop Linux - Newbie 3 01-12-2005 09:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration