awk - Inline reordering of substrings via bash -
assume text file contains specific lines word order should altered. words (substrings) delimited single whitespaces. lines altered can identified first character (e.g., ">").
# cat test.txt >3 test foo bar baz foo bar qux >2 test foo bar baz >1 test foo bar qux
what command (probably in awk
) use apply same ordering process across lines starting key character?
# cat test.txt | sought_command >this test 3 foo bar baz foo bar qux >this test 2 foo bar baz >this test 1 foo bar qux
here's 1 way using awk:
awk 'sub(/^>/, "") { print ">"$3, $4, $2, $1; next } 1' file
sub
returns true (1) when makes substitution. 1
@ end shortest true condition, trigger default action { print }
.
Comments
Post a Comment