简体   繁体   中英

Invoking multi-line (G)AWK program in one line

I'm wondering if it's possible to run a multi-line (G)AWK program through the shell where I can't have tabs or newlines.

It seems to crop up as an issue when I have variable assignments. For instance:

awk '{one=$1 two=$2}'

One possibility is to add semicolons between instructions, as you state.

However, return is also an option in most shells, just hit return before closing the awk instruction:

$ awk '{one=$1
> two=$2}' test.txt

note that > is added by the shell. This is also documented in the manual .

看起来只需添加标准分号就可以做到这一点:

awk '{one=$1;two=$2}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM