Hans
Hans

Reputation: 5505

With the bash shell, how can a cut column be output multiple times

What is the right way to cut columns and print some of them multiple times in the output:

cut -d " " -f1,3,3,4 in > out

does not work.

Upvotes: 1

Views: 844

Answers (2)

bash-o-logist
bash-o-logist

Reputation: 6911

Bash

OLDIFS="$IFS"
while read -r line
do
  set -- $line
  echo "$1 $3 $3 $5"
done <file
IFS="$OLDIFS"

Upvotes: 1

Shawn Chin
Shawn Chin

Reputation: 86844

awk '{print $1" "$3" "$3" "$4}' in > out

Upvotes: 6

Related Questions