Remove Data from Fields


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove Data from Fields
# 1  
Old 01-14-2007
Remove Data from Fields

I would like some sugestions on how to solve the following problem with removing selected data from fields. Each day I receive a file containing 22,000 records that I use a combination of awk and the cut command to remove unwanted fields. This is a work in process as I learn more about awk, sed and other tools.

The problem I am struggling with is how can i remove only the time stamp, days, day from the last field? I only want the number days in the last field. For days less than 1 if I can place a "0" in field great, I think a blank will work for now.

Below is a sample of the file output.
Thanks

|1|8|0|0|10 days, 5:35:33
|1|8|0|0|0:00:00
|1|8|0|0|18 days, 12:08:44
|1|8|0|0|0:09:25
|1|8|0|0|23:59:25
|1|8|0|0|1 day, 1:16:25
# 2  
Old 01-14-2007
Can you show how you want to output to look? I'm not sure I understand what it is exactly you want removed.
# 3  
Old 01-14-2007
I hope this helps.

BEFORE
|1|8|0|0|10 days, 5:35:33
|1|8|0|0|0:00:00
|1|8|0|0|18 days, 12:08:44
|1|8|0|0|0:09:25
|1|8|0|0|23:59:25
|1|8|0|0|1 day, 1:16:25

AFTER
|1|8|0|0|10
|1|8|0|0|0 If <24 hours = 1 or 0
|1|8|0|0|18
|1|8|0|0|0 If <24 hours = 1 or 0
|1|8|0|0|0 If <24 hours = 1 or 0
|1|8|0|0|1
# 4  
Old 01-14-2007
Try:
sed 's/day.*//g;s/[0-9]*:[0-9]*:[0-9]*$/0/'
# 5  
Old 01-15-2007
Perderabo,

Thank you, this worked great!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove range of fields

I am trying to cut a range of fields in awk. The below seems to work for removing field 50, but what is the correct syntax for removing a range ($50-$62). Thank you :). awk awk 'BEGIN{FS=OFS="\t"}{$50=""; gsub(/\t\t/,"\t")}1' test.vcf.hg19_multianno.txt > output.csv Maybe: awk... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. UNIX for Dummies Questions & Answers

Remove zeros from first field, but print all fields

Hello Everyone, I've got a comma-delimited file that looks like this: 0012,123 ,456 ,05/12/2014 0123,525 ,286 ,05/12/2014 0456,791 ,300 ,05/12/2014 1095,759 ,300 ,05/12/2014 1344,576 ,292 ,05/12/2014 1558,551 ,283 ,05/12/2014 002183719, , ... (9 Replies)
Discussion started by: Scottie1954
9 Replies

3. Shell Programming and Scripting

remove records which have 2 same fields

how can i remove records which have 2 same fields? my file: saeed 1 2 sa vahid 2 3 45 reza 212 33 sa amir 1 1 ui reza 21 33 sa i want to remove records which first and 3rd field of that are as the same, here line 3 and 5 must be removed. (3 Replies)
Discussion started by: saeed.soltani
3 Replies

4. Shell Programming and Scripting

Remove rows with first 4 fields duplicated in awk

Hi, I am trying to use awk to remove all rows where the first 4 fields are duplicates. e.g. in the following data lines 6-9 would be removed, leaving one copy of the duplicated row (row 5) Borgarhraun FH9822 ol24 FH9822_ol24_m20 ol Deformed c Borgarhraun FH9822 ol24 ... (3 Replies)
Discussion started by: tomahawk
3 Replies

5. Shell Programming and Scripting

How to remove '-' for date fields alone in a file

Hi, I have a scenario like, I need to replace a hyphens(-) for date field alone in the file. I have minus(-) sign for other fields it should remain as such, only for date fields hyphens must be removed. Please find the content for the file below: sample.txt: -----------... (4 Replies)
Discussion started by: G.K.K
4 Replies

6. Shell Programming and Scripting

remove blank spaces from fields

Hi Friends, I have large volume of data file as shown below. Beganing or end of each filed, there are some blank spaces. How do I remove those spaces? AAA AAA1 | BBB BB1 BB2 |CC CCCC DDDD DD | EEEEEEE EEEEEEEE | FFF FFFFFF FFFF GG GGGGGG |HH HH ... (3 Replies)
Discussion started by: ppat7046
3 Replies

7. Shell Programming and Scripting

Remove specific strings from certain fields

I'm working with a set of files where I'm trying to remove a set of characters from specific fields. The files are comma-delimited, and the characters I want to remove include: - open parentheses - ( - close parentheses - ) - space followed by a dollar sign - $ I don't want to remove every... (1 Reply)
Discussion started by: HLee1981
1 Replies

8. Shell Programming and Scripting

remove extra spaces between fields

Hi, I have a source file as mentioned below: I want to remove all the extra spaces between the fields. a b--------|sa df-------|3232---|3 sf sa------|afs sdf-----|43-----|33 a b c------|adfsa dsf---|23-32|23 *Here '-' idicates spaces Now, I want output as below: a b|sa df|3232|3... (7 Replies)
Discussion started by: srilaxmi
7 Replies

9. Shell Programming and Scripting

How can i remove spaces in between the fields in a file

Hey , I have a file and it's having spaces for some of the fields in it. Like the one below. I want to remove the spaces in them through out the file. The spaces occur randomly and i can't say which field is having space. So please help. Here is sample file with spaces after 5th field. (3 Replies)
Discussion started by: dsravan
3 Replies

10. Shell Programming and Scripting

How to change Raw data to Coloumn data fields

Dear All, I have some data file.see below. --------------ALARM CLEARING FROM SubNetwork=ONRM_RootMo,SubNetwork=AXE,ManagedElement=CGSN-------------- Alarm Record ID: 25196304 Event Time: 2006-08-28 13:41:35 Event Type: ... (1 Reply)
Discussion started by: Nayanajith
1 Replies
Login or Register to Ask a Question