Removing columns using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing columns using awk
# 1  
Old 06-25-2011
Removing columns using awk

HI ,

I have a comma delimiter file, in which I want to remove 8th and 9th column.

I tried removing those columns using the below code

Code:
awk 'BEGIN { FS=","; OFS="," } {$8=$9="";gsub(",+",",",$0)}1' infile

But the problem is 8th and 9th columns are user entered fields, theyvhave carriage returns and multiple "," between the data, so my above code is not removing the whole columns it's removing the data from the first comma it encountered.


Below is the sample data from these columns.

Code:
8th and 9th column  -- I issue was related to ,table load.when uat was going on ,march mentioned the below,
1.abdc,
2.fdfdf, and done


As I said because of multiple comma I am not able to remove the columns properly,please suggest how can I remove these columns.

--Mora
# 2  
Old 06-26-2011
Separators are used to separate columns.
If you have separator as the actual column content (8 and 9), then it's use is invalid.

Check out if you can find separator which is not in the column, something like pipe, then use it during initial retrival of data from source.

Otherwise, post a bigger expected input / output example so folks here can suggest.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns: 4 0.04972604 KLHL28 4 0.0497332 CSTB 4 0.04979822 AIF1 4 0.04983331 DECR2 4 0.04990344 KATNB1 4 4 4 4 How can I remove the trailing... (3 Replies)
Discussion started by: evelibertine
3 Replies

2. Shell Programming and Scripting

Removing columns using awk

HI , I want to remove 5th and 6th column from a .csv file using awk.is there any way of this apart from writing the each field as below awk -F, '{print $1,$2,$3,$7......$100}' OFS=, infile. Thx, Deepti (4 Replies)
Discussion started by: gaur.deepti
4 Replies

3. Shell Programming and Scripting

Removing columns from awk '{ print $0 }'

I have a one-line command, lsusb | awk '{ $1=""; $2=""; $3=""; $4=""; $5=""; $6=""; print $0 }' It works, and gives the results I expect, I was just wondering if I am missing some easier way to nullify the first 6 column variables? Something like, lsusb | awk '{ $(1-6)=""; print $0 }' But... (10 Replies)
Discussion started by: AlphaLexman
10 Replies

4. Shell Programming and Scripting

Removing columns with dashes

My files look like this I need to remove the columns where dashes are the majority, if any of the sequences has any character in that particular position it should be removed too. The IDs and Freqs should be kept intact. Thus, the resulting file should look like this Thanks in advance (14 Replies)
Discussion started by: Xterra
14 Replies

5. Shell Programming and Scripting

finding duplicates in columns and removing lines

I am trying to figure out how to scan a file like so: 1 ralphs office","555-555-5555","ralph@mail.com","www.ralph.com 2 margies office","555-555-5555","ralph@mail.com","www.ralph.com 3 kims office","555-555-5555","kims@mail.com","www.ralph.com 4 tims... (17 Replies)
Discussion started by: totus
17 Replies

6. Shell Programming and Scripting

Removing blank columns from a file

Hi, I have a sample file as shown below -- id parent name dba -----------------------------------... (7 Replies)
Discussion started by: sumirmehta
7 Replies

7. Shell Programming and Scripting

Help removing lines with duplicated columns

Hi Guys... Please Could you help me with the following ? aaaa bbbb cccc sdsd aaaa bbbb cccc qwer as you can see, the 2 lines are matched in three fields... how can I delete this pupicate ? I mean to delete the second one if 3 fields were duplicated ? Thanks (14 Replies)
Discussion started by: yahyaaa
14 Replies

8. UNIX for Dummies Questions & Answers

Removing columns of a file using vi Editor

Hi Experts, I have a file which looks like in this way 1 2233|A.K Shukla |G.M |Sales |12/12/52|6000 2 9876|Jai Sharma |Director |Production |12/03/50|67000 3 5678|Sumit Chakarborty |D.G.M |Marketing |19/04/43|6000 4 2365|Barun... (2 Replies)
Discussion started by: DilipPanda
2 Replies

9. UNIX for Dummies Questions & Answers

Removing lines that are (same in content) based on columns

I have a file which looks like AA BB CC DD EE FF GG HH KK AA BB GG HH KK FF CC DD EE AA BB CC DD EE UU VV XX ZZ AA BB VV XX ZZ UU CC DD EE .... I want the script to give me only one line based on duplicate contents: AA BB CC DD EE FF GG HH KK AA BB CC DD EE UU VV XX ZZ (7 Replies)
Discussion started by: adsforall
7 Replies

10. Shell Programming and Scripting

removing spaces betweent columns

Hello Friends, Can any one help me with this issue: I would like to format a file: say if I have rows like: 4512 , SMITH , I-28984 ,, 4324 , 4343 42312 , SMITH , I-2EE8984 ,, 432E4E4 , 4343 I would like to have the output diaplayed like : 4512... (8 Replies)
Discussion started by: sbasetty
8 Replies
Login or Register to Ask a Question