0

The files is seperated by | pipe symbol

myfile.txt

Hello|how|are|you|hope|you|are|doing|fine
Lilly|jasmine|rose|sunflower|nightfire|flowers

I want to remove columns greater than 3. I want result set as

Hello|how|are
Lilly|jasmine|rose

In actual file i have to remove the extra columns more than 13 columns in each row. Using SED/AWK in unix shell scripting. Thanks !

2
  • Why using sed or awk? cutting fields off feels for a task for cut (e.g. cat testfile | cut -d\| -f 1-3). And why not in a shell script? Or did you mean awk, sed or bash. Or any shell?
    – Hennes
    Jun 8, 2015 at 17:30
  • Also, is it either remove colums "greater than 3" or "more than 13". Both cannot be right.
    – Hennes
    Jun 8, 2015 at 17:31

1 Answer 1

1
cut -d'|' -f1-14 myfile

This works fine! Simple cut would do no need for awk or sed.

1
  • need missing "space" between -f and first index; and should be -f 1-3 to produce requested output, but definite +1 Jun 8, 2015 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .