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"
# 8  
Old 03-27-2008
Quote:
Originally Posted by era
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.
Backslashes work with the parentheses. However, it does not work with \|.
a|b will treat | as a string and a\|b will treat | as special character. but I couldn't find it's meaning in help manual and \| does not work like or.
I have also been researching online.
I'm desperate
# 9  
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
Code:
awk '{print $1,$2,$3}' file

Since I already have sed code for editing other stuffs in the file. Using sed would save me many lines of work. I'm not very familiar with awk and cut, but if I still couldn't get sed to work this afternoon, I'm willing to try anything.
# 10  
Old 03-27-2008
As a really crude hack you could combine the month names into one monster regular expression, with a slight risk of false positives.

Here's a schematic picture:

Code:
J     a    n
J    u    n
J    u    l
F    e    b
M    a    r
M    a    y
A    p    r
A    u    g
S    e    p
O    c    t
N    o    v
D    e    c
------------
JFM  aue nlb
ASO pco ryg
ND     ptvc

That probably comes out hideously ugly, but the basic observation is that the first character of a month name can be J or F or M or A or S or O or N or D, and so on for the second and third letters. So you could lump them together and just accept the risk that somebody writes something which begins with Jay or Opp and happens to look enough like a date to trigger a false match.

[ADFJMNOS][aceopu][bcglnprtvy]

Hope I didn't miss any.

I would not do this, but you said you were desperate ... at that point the awk or cut commands hinted at above would seem like better solutions.

Last edited by era; 03-27-2008 at 12:42 PM.. Reason: Missed some after all (-:
# 11  
Old 03-27-2008
Just out of curiosity, which platform is this on? Does sed --version print anything useful? Does which sed or type sed reveal any alternate seds in your PATH which might work better?
# 12  
Old 03-27-2008
Quote:
Originally Posted by era
Just out of curiosity, which platform is this on? Does sed --version print anything useful? Does which sed or type sed reveal any alternate seds in your PATH which might work better?
I'm working on Solaris and sed --version does not print anything useful.
I also had the idea of doing something like [ADFJMNOS][aceopu][bcglnprtvy], but it's very risky since I'm edit a database file which contains lots of data.

also, another question:
(Jan or Feb or...) (1 space or two space) ([0-9][0-9] or [0-9]) [12][0-9][0-9][0-9]
For example, the data format can be Mar 26 2008, Mar 6 2008, Mar 6 2008.
Do you have any good suggestion about (1 space or 2 space) ([0-9][0-9] or [0-9]) part without using \|?

Thank you for my life lol
# 13  
Old 03-27-2008
Code:
 [ 0-9]?[0-9]

The ? operator means the previous character is optional but if your sed is really old, itmight not understand that either. (Some seds want a backslash in order to make the question mark special, too.) There's a space there before the first visible character.

You could still try the following, in increasing order of desperation.

Code:
locate bin/sed
locate bin/gsed
ls -l /opt/contrib/unsupported/dangerous/communist/contraband/hate/hate/hate/gnu/bin/sed  # long shot (-:
find / \( -name sed -o -name gsed \) >/tmp/found.sed 2>/dev/null &  # leave it for the night

# 14  
Old 03-27-2008
Quote:
Originally Posted by era
Code:
 [ 0-9]?[0-9]

The ? operator means the previous character is optional but if your sed is really old, itmight not understand that either. (Some seds want a backslash in order to make the question mark special, too.) There's a space there before the first visible character.

You could still try the following, in increasing order of desperation.

Code:
locate bin/sed
locate bin/gsed
ls -l /opt/contrib/unsupported/dangerous/communist/contraband/hate/hate/hate/gnu/bin/sed  # long shot (-:
find / \( -name sed -o -name gsed \) >/tmp/found.sed 2>/dev/null &  # leave it for the night

ah~u r right, ? also doesnt work. I will try the long code tonight.
Thank you
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