Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

issue with field separators 1

Status
Not open for further replies.

w5000

Technical User
Joined
Nov 24, 2010
Messages
223
Location
PL

hello,
could someone please explain why the second command doesn't produce the same output?
Must the "-" in my example be always the first on separator list?
Code:
$ echo "aaaa-bbbb cccc dddd.eeee"|awk -F["[red]-[/red]|[blue].[/blue]| "] '{print $1"\n"$2"\n"$3"\n"$4"\n"$5}'
aaaa
bbbb
cccc
dddd
eeee
$ echo "aaaa-bbbb cccc dddd.eeee"|awk -F["[blue].[/blue]|[red]-[/red]| "] '{print $1"\n"$2"\n"$3"\n"$4"\n"$5}'
aaaa-bbbb
cccc
dddd
eeee

$
 
Hi

Dash ( - ) has special meaning inside character classes, unless enumerated at one end or escaped.
[ul]
[li][tt][-|.| ][/tt] means any of the characters "-", "|", ".", "|" or " ".[/li]
[li][tt][.|-| ][/tt] means any of the characters ".", a character from "|" to "|" or " ".[/li]
[/ul]

By the way, alternation not works in character classes. You probably want [tt][-. ][/tt], [tt][.\\- ][/tt], or [tt]\\.|-| [/tt].


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top