Deleting column from a flatfile with delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting column from a flatfile with delimiter
# 1  
Old 06-06-2008
Deleting column from a flatfile with delimiter

I have a set of flatfiles which have columns delimited by #. How can a particular column be deleted in all the flatfiles. All flatfiles have same number of columns.
# 2  
Old 06-07-2008
Code:
$ cat filea
a#b#c
d#e#f
g#h#i

if you have to delete the 2nd column,

$ awk 'BEGIN{FS=OFS="#"}{$2=""}{print}' filea
a##c
d##f
g##i

or 

$ awk 'BEGIN{FS=OFS="#"}{$2="";gsub(FS "+",FS)}1' filea
a#c
d#f
g#i

//Jadu
# 3  
Old 10-03-2008
Hi,
Thanks for the reply. Can you please clarify one point. What is "1' at the end of the braces mean.
# 4  
Old 10-03-2008
Quote:
Originally Posted by rsprabha
Hi,
Thanks for the reply. Can you please clarify one point. What is "1' at the end of the braces mean.
1 => print
# 5  
Old 10-03-2008
Thanks a lot once again.
# 6  
Old 10-03-2008
Or cut -d '#' -f1,3- file
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace specific column delimiter

Hi All, I have a file with a pipe delimiter. I need to replace the delimiter with html tags. I managed to get all the delimiters replaced along with first and last but the requirement is that I need to change 7th delimiter with slight change. File1: ... (2 Replies)
Discussion started by: shash
2 Replies

2. Shell Programming and Scripting

Ignore delimiter within a column

Hi, So I was trying this awk snippet awk -F, '$1 ~ /Match/' File This is my sample file output Name,Age,Nationality,Description Jack,20,American,Tall, caucasian, lean Mary,30,British,Short,white,slim I would expect expected Output to be, when a certain match is met say $1 is... (2 Replies)
Discussion started by: sidnow
2 Replies

3. Shell Programming and Scripting

Remove the values from a certain column without deleting the Column name in a .CSV file

(14 Replies)
Discussion started by: dhruuv369
14 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

5. Shell Programming and Scripting

Column to row with delimiter

Hi, i have data in a file f1.txt a b c d and i want to print the above column values in single line with a delimiter, say ',' The output should look like: a,b,c,d I could find rows to columns help online but not vice versa Thanks, -srinivas yelamanchili (4 Replies)
Discussion started by: ysrini
4 Replies

6. Shell Programming and Scripting

rearrange the column names with comma as column delimiter

Hi, I am new to shell scripting, i have requirement can any one help me out in this regrads, in directory i have file like invoice1.txt, invoice2.txt in each file i have fixed number of columns, 62 in number but they are randomly arranged.like for first file invoice1.txt can have columns... (5 Replies)
Discussion started by: madhav62
5 Replies

7. Shell Programming and Scripting

Finding a flatfile & deleting first line

I have a small script where I want to see if a file exists & then delete the first line from it. I have code to help me find if the file exists, but I am unsure as to how to then take in the answer and remove the first line from the flatfile: This is what I have so far just to output if the... (3 Replies)
Discussion started by: fatalxkiss
3 Replies

8. Shell Programming and Scripting

Deleting a line from a flatfile using Shell Script

Hi All, Can Anyone please tell me,how can I delete a line from a file. I am reading the file line by line using whil loop and validating each line..Suppose in the middle i found a particular line is invalid,i need to delete that particular line. Can anyone please help. Thanks in advance,... (14 Replies)
Discussion started by: dinesh1985
14 Replies

9. UNIX for Dummies Questions & Answers

Finding a column in a flatfile

I have a file which is fixed width columns. This is an offset buffer - rather than space or tab delimited. There are upto about 8 columns and I need to get all of the column 5's values into another file. The problem is that because the delimiter is a space - and some fields are blank - the 5th... (3 Replies)
Discussion started by: peter.herlihy
3 Replies
Login or Register to Ask a Question