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

1 Answer 1

5

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
  • ...
Sign up to request clarification or add additional context in comments.

2 Comments

Minor detail, but you can just do awk -F_ instead of awk -F"_".
You can golf it further with: awk -F_ '{ print $1, $2, $3"_"$4 }'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.