jbsu32
jbsu32

Reputation: 1064

Bash: splitting items from a definite column

How can I fix this??

Original problem link : https://www.hackerrank.com/challenges/text-processing-cut-5?h_r=next-challenge&h_v=zen

Upvotes: 0

Views: 94

Answers (3)

jbsu32
jbsu32

Reputation: 1064

cut -f-2 <- The Answer of my question

cut -f-3 <- The answer to the HackerRank Problem, as it has some indentation problem

(I'm just splitting by the tab and taking the first two parts.)

Upvotes: 1

Andr&#233;
Andr&#233;

Reputation: 19

You want this?

cut -d $'\t' -f-3

Upvotes: 0

Jacek Trociński
Jacek Trociński

Reputation: 920

You can use awk to do this very simply:

echo -e "1   New York, New York[10]  8,244,910\t1 New York-Northern New Jersey-Long Island, NY-NJ-PA MSA  19,015,900\t1   New York-Newark-Bridgeport, NY-NJ-CT-PA CSA 22,214,083" | awk -F '\t' ' { print $1 } '

Output:

1   New York, New York[10]  8,244,910

Upvotes: 1

Related Questions