diplosaurus
diplosaurus

Reputation: 2588

Alias of awk command - too many quotes

Probably missing something simple here but I am not a shell scripting expert.

I have a local command that works perfectly.

tail -f /path/to/file | awk '
  /INFO/ {print "\033[32m" $0 "\033[39m"}
  /ERROR/ {print "\033[31m" $0 "\033[39m"} 
  /WARNING/ {print "\033[33m" $0 "\033[39m"}
'

If I ssh into my boxes and paste it in, it works well. But I can't seem to alias it because it's already using both kinds of quotes, so alias='...' won't work. I've also tried making it into a function:

function tailMyFile {
    tail -f /path/to/file | awk '
    /INFO/ {print "\033[32m" $0 "\033[39m"}
    /ERROR/ {print "\033[31m" $0 "\033[39m"} 
    /WARNING/ {print "\033[33m" $0 "\033[39m"}'; 
}

Which tells me: -bash: /INFO/: No such file or directory

Upvotes: 0

Views: 295

Answers (1)

Isaac
Isaac

Reputation: 310

try this way of function declaration:

tailMyFile() {
    tail -f /path/to/file | awk '
    /INFO/ {print "\033[32m" $0 "\033[39m"}
    /ERROR/ {print "\033[31m" $0 "\033[39m"} 
    /WARNING/ {print "\033[33m" $0 "\033[39m"}'; 
}

However, it seems as though your error is not pertaining to how the functions is defined, but whether your /INFO/ directory is properly seen, can you cd /INFO without any problems?

Upvotes: 1

Related Questions