2

I have csv file with 80 columns and "^A" delimiter. I want to delete few columns from it, can be 1,2,20,31,45,56,77,78,79,80 or what ever column needed.

For Example: I am taking a CSV file with 15 columns From:

2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  
2018^A04 14:14:46^A01^AJHFM^A2^ACard^Aacc^A11^A0^AVZ^Aapp^A2^AGold^ACUST^ABB  

To:

I deleted columns 2,5,7,9,13

2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  
2018^A01^AJHFM^ACard^A11^AVZ^Aapp^A2^ACUST^ABB  

It worked using awk but it's giving empty spaces in the deleted columns.

awk 'BEGIN { FS="^A"} {$1=$2="";gsub(",+",",",$0)}1' filename
1
  • This command is working "cut -f2-4,77-78 -d $'\x01' ". But the only thing I have to select all the columns I need not other way around. Commented Aug 2, 2018 at 21:49

1 Answer 1

1

when you assign to a field, awk will rewrite the line using the output field separator. You need to set that, as by default it is a space. Do this:

BEGIN { FS = OFS = "^A" }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.