Visit Our UNIX and Linux User Community


Remove Specific Column in a File using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove Specific Column in a File using awk
# 1  
Old 07-01-2013
Remove Specific Column in a File using awk

Hi,

I would like to ask your expertise to remove specific column no. 8 in the below file using but I don't have an idea on how to simply do this using awk command. Appreciate your help in advance.

Input f:
Code:
ABC 1 1XC
CDA 1 2YC
CCC 1 3XC
AVD 1 3XA

Expected output file:
Code:
ABC 1 1C
CDA 1 2C
CCC 1 3C
AVD 1 3A


Last edited by Franklin52; 07-01-2013 at 07:28 AM.. Reason: Code tags
# 2  
Old 07-01-2013
Your sample contains only 3 columns. Also 3rd column itself it not removing completely.
Please be specific and provide correct sample data.
# 3  
Old 07-01-2013
Code:
perl -F -ane '$F[7]=""; print @F' file

Code:
awk 'BEGIN{FS=""; OFS=""} {$8=""}'1 file

# 4  
Old 07-01-2013
you can do this using sed,

Code:
sed -e 's/\(.......\)\(.\)\(.\)/\1\3/' inputfile.txt

# 5  
Old 07-01-2013
Quote:
Originally Posted by clx
Your sample contains only 3 columns. Also 3rd column itself it not removing completely.
Please be specific and provide correct sample data.
Sorry, if you find my question somewhat misleading. But I refer to the position/column no. 8 to be removed in the sample data.

Column 8:
Code:
X
Y
X
X

Input file:
Code:
ABC 1 1XC
CDA 1 2YC
CCC 1 3XC
AVD 1 3XA

Output file:
Code:
ABC 1 1C
CDA 1 2C
CCC 1 3C
AVD 1 3A


Last edited by Franklin52; 07-01-2013 at 07:29 AM.. Reason: Code tags
This User Gave Thanks to zzavilz For This Post:
# 6  
Old 07-01-2013
cut option..

Code:
 
cut -c 1-7,9- filename

This User Gave Thanks to vidyadhar85 For This Post:
# 7  
Old 07-01-2013
Quote:
Originally Posted by vidyadhar85
cut option..

Code:
 
cut -c 1-7,9- filename


Thanks! This code seems to work fine...

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

2. Shell Programming and Scripting

awk to remove lines in file if specific field matches

I am trying to remove lines in the target.txt file if $5 before the - in that file matches sorted_list. I have tried grep and awk. Thank you :). grep grep -v -F -f targets.bed sort_list grep -vFf sort_list targets awk awk -F, ' > FILENAME == ARGV {to_remove=1; next} > ! ($5 in... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

4. Shell Programming and Scripting

Awk: Need help replacing a specific column in a file by part of a column in another file

Hi, I have two input files as File1 : ABC:client1:project1 XYZ:client2-aa:project2 DEF:client4:proj File2 : client1:W-170:xx client2-aa:WT-04:yy client4:L-005A:zz Also, array of valid values can be hardcoded like Output : ABC:W:project1 XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies

5. Shell Programming and Scripting

How to remove delimiter from specific column?

I have 5 column in sample txt file where in i have to create report based upon 1,3 and 5 th column.. I have : in first and third coulmn. But I want to retain the colon of fifth coulmn and remove the colon of first column.. 5th column contains String message (for example,... (7 Replies)
Discussion started by: Shirisha
7 Replies

6. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

7. UNIX for Dummies Questions & Answers

How to remove a string from a specific column in a file

Hello, A basic query. How can I remove a string from a specific column. For example, remove "abcd" just from column 2 in example file: abcd abcd1 abcd abcd2 abcd abcd3 to get output: abcd 1 abcd 2 abcd 3 Thank you!:) (4 Replies)
Discussion started by: auburn
4 Replies

8. Shell Programming and Scripting

Need an awk for a global find/replace in a file, specific column

I am new to unix and awk/sed etc... using C-Shell. Basically, I have a fixed length file that has 4 different record types on it, H, D, V, W all in column 1. I need to change all the W's in column 1 to D's. in the entire file. The W's can be anywhere in the file and must remain in the same... (3 Replies)
Discussion started by: jclanc8
3 Replies

9. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

Featured Tech Videos