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 !

  • 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 '15 at 17:30
  • Also, is it either remove colums "greater than 3" or "more than 13". Both cannot be right. – Hennes Jun 8 '15 at 17:31
1
cut -d'|' -f1-14 myfile

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

  • need missing "space" between -f and first index; and should be -f 1-3 to produce requested output, but definite +1 – Marco M. von Hagen Jun 8 '15 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.