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-foption - the
gensubfunction used on$1in 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
- if replacement possible, expression true , modifies
Comments
Post a Comment