How to remove delimiter from specific column?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove delimiter from specific column?
# 1  
Old 10-12-2010
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, $5=string1:string2:String3)
and 1st column contains full path of script execution (for example, $1=path:MM/DD/YYYY HH:MM:SS ) As I have to extract path from $1 I have given awk -F':|] ' ' but checks for all colon every line.

Can anyone please guide me how to remove : from $1 only.
Thanks in advance.
# 2  
Old 10-12-2010
Hi, please provide a sample input file and specify desired output. Also could you show what you tried so far?
# 3  
Old 10-12-2010
Here is the command which i formed working properly. But the problem occurs when My Messages is having colon in it. Only part of message gets displayed (the part after : that only Message3 displayed)

My output looks like:
Code:
,Filename,Error Message,Count

Code:
cat sample.txt | awk -F':|] ' '/ERROR|INFO/{ split($1,fn,"/");
  for (i in fn)
    if(fn[i]~/^snow|^thunder/) {
      ind=i
      strval=fn[ind]
      sub(".*/"strval"/","",$1)
      val=strval","$1
    }
    if (fn[i] !~ /^snow|^thunder/) {
      sub(".*/","",$1)
      OFS=","
      val=strval","$1
    }

    a[val OFS $NF]++
  }
  END{for(j in a)print j,a[j]}'| sort -k1,3

Content of sample.txt
Code:
/mylogsfolderpath/logs/nrf*Log20100930.log/09/30/2010/12:10:04 INFO [UNKNOWN] INFO Message.
/mylogsfolderpath/logs/nrf*220100929.log/09/29/2010/11:35:16 ERROR [12857745252700] Error Message
/mylogsfolderpath/logs/nrf*220100928.log/09/29/2010/11:45:16 ERROR [12857745652700] Error Message1:Message2:Message3

Moderator's Comments:
Mod Comment This code was almost unreadable, so I've reformatted it

Last edited by Scott; 10-12-2010 at 07:28 AM.. Reason: Code tags, formatting
# 4  
Old 10-12-2010
Simply what is the output you desire from this input:
Code:
Content of sample.txt
/mylogsfolderpath/logs/nrf*Log20100930.log/09/30/2010/12:10:04 INFO [UNKNOWN] INFO Message.
/mylogsfolderpath/logs/nrf*220100929.log/09/29/2010/11:35:16 ERROR [12857745252700] Error Message
/mylogsfolderpath/logs/nrf*220100928.log/09/29/2010/11:45:16 ERROR [12857745652700] Error Message1:Message2:Message3

# 5  
Old 10-12-2010
Code:
,filename,ErrorMessage:ErrorMessage:ErrorMessage,Count
,filename,InfoMessage,Count

# 6  
Old 10-12-2010
What did you mean with filename? are these filenames that you mentioned?
Code:
nrf*Log20100930.log
nrf*220100929.log
nrf*220100928.log

And besides what is the count? count of error messages? like 3 for "Message1:Message2:Message3" ?
# 7  
Old 10-12-2010
Output I am getting is correct...
I have just provided the output format...
where
Filename.log,Error String,1
Filename.log,Message3,2

Here problem is below code
awk -F':|]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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

Remove lines matching a substring in a specific column

Dear group, I have following input text file: Brit 2016 11 18 12 00 10 1.485,00 EUR Brit 2016 11 18 12 00 10 142,64 EUR Brit 2016 11 18 12 00 10 19,80 EUR Brit 2016 11 18 12 00 10 545,00 EUR Brit 2016 11 18 12 00 10 6.450,00 EUR... (3 Replies)
Discussion started by: gfhsd
3 Replies

3. UNIX for Advanced & Expert Users

How to remove the delimiter from the column value within a file?

Hello All, we have some 10 files wherein we are using the ASCII NULL as separator which is nothing but '^@' and we need to change it to pipe delimited file before loading to database. Most of the data seems to be fine but there are instances where this separator tends to appear in the middle of... (9 Replies)
Discussion started by: dJHa
9 Replies

4. 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

5. 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

6. Shell Programming and Scripting

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: ABC 1 1XC CDA 1 2YC CCC 1 3XC AVD 1 3XA Expected output file: ABC 1 1C CDA... (9 Replies)
Discussion started by: zzavilz
9 Replies

7. Shell Programming and Scripting

how to remove tab space only in the column of a specific row

Hi, I need help to remove tab delimited space in the $2 of a specific row. My file is like this:- file1.txt No_1 4 139 156 No_1 5 161 205 No_4 91 227 212 No_19 254 243 263 No_19 645 249 258 No_19 101 2492 2635 No_90 8 277 288... (5 Replies)
Discussion started by: redse171
5 Replies

8. Shell Programming and Scripting

remove special character from a specific column

Hello , i have a text file like this : A123 c12AB c32DD aaaa B123 23DS 12QW bbbb C123 2GR 3RG cccccc i want to remove the numbers from second and third column only. i tried this : perl -pe 's///g' file.txt > newfile.txt but it will remove the number from... (7 Replies)
Discussion started by: shelladdict
7 Replies

9. 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

10. 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
Login or Register to Ask a Question