INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

"]" as field separator in awk

"]" as field separator in awk

(OP)

hello,
is there any mistake in separator list given as

CODE -->

"[\[|\/|\]]" 

The first two separators [ and / seems to work but the last ] not.

CODE --> lab

$ grep saved out|tail -10
2015-03-10 11:12:12 (846 KB/s) - 'U862861.bff' saved [345088/345088]
2015-03-10 11:12:13 (39.9 MB/s) - 'U862862.bff' saved [6144/6144]
2015-03-10 11:12:13 (58.3 MB/s) - 'U862863.bff' saved [8192/8192]
2015-03-10 11:12:13 (49.2 MB/s) - 'U862864.bff' saved [7168/7168]
2015-03-10 11:12:13 (38.8 MB/s) - 'U862865.bff' saved [6144/6144]
2015-03-10 11:12:13 (41.7 MB/s) - 'U862866.bff' saved [5120/5120]
2015-03-10 11:12:13 (43.4 MB/s) - 'U862867.bff' saved [6144/6144]
2015-03-10 11:12:14 (42.7 MB/s) - 'U862868.bff' saved [7168/7168]
2015-03-10 11:12:14 (44.8 MB/s) - 'U862869.bff' saved [5120/5120]
2015-03-10 11:12:14 (28.2 MB/s) - 'U862870.bff' saved [13312/13312]
$ grep saved out|tail -10|awk -F"[\[]" '{print $NF}'
345088/345088]
6144/6144]
8192/8192]
7168/7168]
6144/6144]
5120/5120]
6144/6144]
7168/7168]
5120/5120]
13312/13312]
$ grep saved out|tail -10|awk -F"[\[|\/]" '{print $NF}'
345088]
6144]
8192]
7168]
6144]
5120]
6144]
7168]
5120]
13312]
$ grep saved out|tail -10|awk -F"[\[|\/|\]]" '{print $NF}'
2015-03-10 11:12:12 (846 KB/s) - 'U862861.bff' saved [345088/345088]
2015-03-10 11:12:13 (39.9 MB/s) - 'U862862.bff' saved [6144/6144]
2015-03-10 11:12:13 (58.3 MB/s) - 'U862863.bff' saved [8192/8192]
2015-03-10 11:12:13 (49.2 MB/s) - 'U862864.bff' saved [7168/7168]
2015-03-10 11:12:13 (38.8 MB/s) - 'U862865.bff' saved [6144/6144]
2015-03-10 11:12:13 (41.7 MB/s) - 'U862866.bff' saved [5120/5120]
2015-03-10 11:12:13 (43.4 MB/s) - 'U862867.bff' saved [6144/6144]
2015-03-10 11:12:14 (42.7 MB/s) - 'U862868.bff' saved [7168/7168]
2015-03-10 11:12:14 (44.8 MB/s) - 'U862869.bff' saved [5120/5120]
2015-03-10 11:12:14 (28.2 MB/s) - 'U862870.bff' saved [13312/13312]
$ grep saved out|tail -10|sed s/$/\ extra/|awk -F"[\[|\/|\]]" '{print $NF}'
2015-03-10 11:12:12 (846 KB/s) - 'U862861.bff' saved [345088/345088] extra
2015-03-10 11:12:13 (39.9 MB/s) - 'U862862.bff' saved [6144/6144] extra
2015-03-10 11:12:13 (58.3 MB/s) - 'U862863.bff' saved [8192/8192] extra
2015-03-10 11:12:13 (49.2 MB/s) - 'U862864.bff' saved [7168/7168] extra
2015-03-10 11:12:13 (38.8 MB/s) - 'U862865.bff' saved [6144/6144] extra
2015-03-10 11:12:13 (41.7 MB/s) - 'U862866.bff' saved [5120/5120] extra
2015-03-10 11:12:13 (43.4 MB/s) - 'U862867.bff' saved [6144/6144] extra
2015-03-10 11:12:14 (42.7 MB/s) - 'U862868.bff' saved [7168/7168] extra
2015-03-10 11:12:14 (44.8 MB/s) - 'U862869.bff' saved [5120/5120] extra
2015-03-10 11:12:14 (28.2 MB/s) - 'U862870.bff' saved [13312/13312] extra

$ grep saved out|tail -10|awk -F"[\[|\/]" '{print $(NF-1),$NF}'|awk -F"]" '{print $1}'
345088 345088
6144 6144
8192 8192
7168 7168
6144 6144
5120 5120
6144 6144
7168 7168
5120 5120
13312 13312 

RE: "]" as field separator in awk

2
Hi

The backslash ( \ ) is meaningful for the shell too. And there you seem to mix character classes and alternation. These work with gawk and mawk running in bash :
  • -F "[\\\\[/\\\\]]"
  • -F "\\\\[|/|\\\\]"
  • -F '[\\[/\\]]'
  • -F '\\[|/|\\]'

Feherke.
feherke.ga

RE: "]" as field separator in awk

(OP)
thank you, these two worked on AIX in ksh and awk:

CODE --> text

# grep saved out|tail -10|awk -F "\\\\[|/|\\\\]" '{print $(NF-2),$(NF-1)}'
345088 345088
6144 6144
8192 8192
7168 7168
6144 6144
5120 5120
6144 6144
7168 7168
5120 5120
13312 13312
# grep saved out|tail -10|awk -F '\\[|/|\\]' '{print $(NF-2),$(NF-1)}'
345088 345088
6144 6144
8192 8192
7168 7168
6144 6144
5120 5120
6144 6144
7168 7168
5120 5120
13312 13312 

RE: "]" as field separator in awk

Another trick, if the first character in a character class is ], it is treated literally. Likewise if the last character is [. So this should also work:

CODE

awk -F '[]/[]' '{print $(NF-2),$(NF-1)}' 

And you aren't in \\\\\escape hell... smile

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close