sed remove date ex. "Mar 25 2008"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed remove date ex. "Mar 25 2008"
# 1  
Old 03-26-2008
Error sed remove date ex. "Mar 25 2008"

is there any way to remove data out of a file with sed?

sample file:
2 3 414 Mar 25 2008
223 312 4244 Feb 25 2008
5 312 422344 Sept 25 2008

output:
2 3 414
223 312 4244
5 312 422344
# 2  
Old 03-26-2008
Code:
sed 's/ \(Jan\|Feb\|Ma[ry]\|Apr\|Ju[nl]\|... you get the idea\) [0-9][0-9] [12][0-9][0-9][0-9]$//'

Grappling with the y3k problem and filling in the missing months left as an exercise. Are dates less than ten space-padded or zero-padded, or not padded at all?
# 3  
Old 03-27-2008
Quote:
Originally Posted by era
Code:
sed 's/ \(Jan\|Feb\|Ma[ry]\|Apr\|Ju[nl]\|... you get the idea\) [0-9][0-9] [12][0-9][0-9][0-9]$//'

Grappling with the y3k problem and filling in the missing months left as an exercise. Are dates less than ten space-padded or zero-padded, or not padded at all?
Hi era,
I still have a problem with removing multiple month.
I could get it to remove one month like this:
sed 's/ Ma[ry] [0-9][0-9] [12][0-9][0-9][0-9]//' file
but the or part of \(Jan\|Feb\|Ma[ry]\) doesn't work.
I'm still trying to get it.

Last edited by katrvu; 03-27-2008 at 10:46 AM..
# 4  
Old 03-27-2008
(Jan or Feb or...) (1 space or two space) ([0-9][0-9] or [0-9]) [12][0-9][0-9][0-9]
Any suggestions? I don't have GNU sed

Last edited by katrvu; 03-27-2008 at 11:20 AM..
# 5  
Old 03-27-2008
use awk, a more suitable tool. If the start of date is always the 4th field and onwards
Code:
awk '{print $1,$2,$3}' file

# 6  
Old 03-27-2008
There are various sed dialects; see the sed manual page's section on regular expressions to figure out what it understands exactly. It might not want backslashes in front of the parentheses and alternation characters.
# 7  
Old 03-27-2008
Quote:
Originally Posted by ghostdog74
use awk, a more suitable tool. If the start of date is always the 4th field and onwards
Well, under those constraints, even cut would cut it (sic). But a good observation as such.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed how to remove "forward shash"

I am trying to remove "forward shash" using sed it was not working 666,server1, 00973 N/A RDF1+TDEV RW 1035788 i need to remove " N/A" and "RW" I need output 666,server, 00973 , RDF1+TDEV , 1035788 (4 Replies)
Discussion started by: ranjancom2000
4 Replies

2. Shell Programming and Scripting

remove the ".0" of a date

Hi, I want to transform a txt file to make a new one. I want to remove the ".0" of the dates only (after the time, there is ".0" that I dont need. I.e 1480.1 1.0 1.0 2012-07-08 23:38:11.0 2012-07-08 23:40:14.0 I want to transform this line to get this new one... 1480.1 ... (3 Replies)
Discussion started by: edgar.piquer
3 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

8. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

9. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

10. UNIX for Dummies Questions & Answers

converting date format: "May 31 2008" to "2008-05-31"

I have the following script to find out the last day of the last month .... and the output of this script is in the following format ... Script goes like this .... #!/bin/ksh cur_month=`date +%m` cur_year=`date +%Y` prev_month=$(($cur_month-1)) # Check to see if this is January if ... (8 Replies)
Discussion started by: santosham
8 Replies
Login or Register to Ask a Question