using awk to selectively change word order in a column -


i want change text:

fred flintstone:father:male wilma flintstone:mother:female flintstone, pebbles:daughter:female barney rubble:father:male rubble, betty:mother:female bam bam rubble:son:male 

into:

flintstone, fred:father:male flintstone, wilma:mother:female flintstone, pebbles:daughter:female rubble, barney:father:male rubble, betty:mother:female rubble, bam bam:son:male 

is possible in 1 line of awk? or better extract first column manipulate text , reimport column?

here gawk 1 liner:

awk -f: '$1=gensub(/([^,]+)[ ]+([^ ,]+)/,"\\2, \\1","1",$1)' yourfile 
  • it uses : delimiter -f option
  • the gensub function used on $1 in pattern part:
    • if replacement possible, expression true , modifies $1
      • the default action print used implicitly.
    • if expression not match (due comma in $1) line implicitly printed

Comments

Popular posts from this blog

java - unable show chart in xls document using jasper reports -

javascript - How to change image src on success AJAX -

java.lang.RuntimeException: Could not generate dummy secret at sun.security.ssl.RSAClientKeyExchange.<init> -