tags:

views:

79

answers:

1

I have field like

a_b_c_d

I want as the output a b c_d, this query wont work for this

awk -F"_" <file> | '{print $1,$2,$3}'

Since it will only print a b c

+4  A: 

Try

awk -F"_" -f <file> '{ print $1" "$2" "$3"_"$4 }'

In other words,

$echo a_b_c_d | awk -F"_" '{ print $1" "$2" "$3"_"$4 }'      
a b c_d

The code in the brackets means

  • print the first match
  • print space
  • print the second match
  • print space
  • ...
Masi
Minor detail, but you can just do `awk -F_` instead of `awk -F"_"`.
Mark Rushakoff
yes, the simplest solution is to print the _ implicitly.
dalloliogm