1

So I was able to get a command finally with the ability to get and grep the information from a specific file I wanted and then I ran into a problem with alias:

find ./ -type f -name filename.ext  -exec grep 'information' {} + | sort | awk -v OFS='\n' '{print $5, $1, $2, $3 }'

From there I was able to figure out that I needed to change my alias after looking it up and I did it as such:

find ./ -type f -name filename.ext  -exec grep 'information' {} + | sort | awk -v OFS='\n' '{print \$5, \$1, \$2, \$3 }'

So now it prints but I still wanted to use the OFS but I am not sure the syntax to get the OFS to load. Thanks in advance!

 alias aliascommand="find ./ -type f -name filename.ext  -exec grep 'information' {} + | sort | awk -v \OFS='\t' '{print \$5 \$1 \$2 \$3 }'"

A variation of the above is what I put into my alias.

closed as unclear what you're asking by Kusalananda, Tomasz, jasonwryan, slm Jun 28 '18 at 3:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What's the alias? – Kusalananda Jun 27 '18 at 20:20
  • edited this to show the alias. – trazinaz Jun 27 '18 at 21:04
  • I'm not sure why you have the backslash before OFS, but I also can't see any problems with that, with or without the backslash. – ilkkachu Jun 27 '18 at 21:14
0

If you do:

alias foo="...'{print $5 $1 $2 $3 }'"

The positional parameters will be expanded when the alias is set. They are within a double-quoted string, after all. You don't want that, so you had to escape them with backslashes. Alternatively, you could have put the whole alias text in single-quotes, but since you want to use single quotes in the alias, that gets rather difficult.

That \n should be fine within the double quotes, though.

In any case, you should probably use a function instead. That way you don't need to think about the extra level of quoting around the commands.

mycommand() {
    find ./ -type f -name filename.ext -exec grep 'information' {} + |
       sort |
       awk -v OFS='\n' '{print $5, $1, $2, $3 }'
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.