Sponsored Content
Top Forums Shell Programming and Scripting Trying to change date separator with sed Post 302340141 by RadRod on Sunday 2nd of August 2009 11:43:46 PM
Old 08-03-2009
Trying to change date separator with sed

Hi there

I am trying to convert some date seperators in a large newline delimited file. each line i am interested in has a date in the format 27/05/2009 all I want is to convert the slashes to tildes(~) I have come up with the following code but it does nothing.

Code:
 
sed 's/\([0-9]\{2\}\)\/\([0-9]\{2\}\)\/\([0-9]\{4\}\) / \1~\2~\3 /' alltrans.test > at3.txt
 
or
 
sed 's_%([0-9]%{2%}%)%/%([0-9]%{2%}%)%/%([0-9]%{4%}%) _%1~%2~%3_' alltrans.test > at3.txt

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Move A File With Same Date,don't Change The Desitination Dir Date

Assume, I created one file three years back and I like to move the file to some other directory with the old date (Creation date)? Is it possible? Explain? (1 Reply)
Discussion started by: jee.ku2
1 Replies

2. UNIX for Dummies Questions & Answers

Change field separator of grep from : to space

Hi, All, I wonder how to change the field separator of grep from : to space when use grep to display. for example when I use grep -e 'pattern1' -e 'pattern2' -n filename to find patterns, it use : to separate patterns, but I want to use blank space. is there an option I can set to... (2 Replies)
Discussion started by: Jenny.palmy
2 Replies

3. Shell Programming and Scripting

dynamically change awk Field Separator FS

Hi All, I was wondering if anyone knew how to dynamically change the FS in awk to accept vairiable containing a field separator. the current code is as below and does not work when i introduce the dynamic FS change :-( validate_source_file() { source_file=$1 ... (2 Replies)
Discussion started by: satnamx
2 Replies

4. UNIX for Dummies Questions & Answers

Sed - Get Separator From String

Hi All, I have the following data in a korn shell variable: a="FirstValue|SecondValue|ThirdValue" The value between "FirstValue", "SecondValue" and "ThirdValue" can change, in this case is a comma: "," and I need to print it only once. I need to know what is the separator value. I... (3 Replies)
Discussion started by: felipe.vinturin
3 Replies

5. Shell Programming and Scripting

Format of SED command to change a date

I have a website. I have a directory within it with over a hundred .html files. I need to change a date within every file. I don't have an easy way to find/replace. I need to change 10/31 to 11/30 on every single page at once. I tried the command below but it didn't work. Obviously I don't know... (3 Replies)
Discussion started by: ijustsawmars
3 Replies

6. Shell Programming and Scripting

sed to insert a separator

My txt file consists of records with 6 numbers followed by 3 characters. Is there a simple “sed” which will insert a | separator between the 6th and 7th position ? Many thanks (3 Replies)
Discussion started by: malts18
3 Replies

7. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (0 Replies)
Discussion started by: ust3
0 Replies

8. Shell Programming and Scripting

sed multilines + separator confusion !!

Hi Seders, i am new to this forum, but i think it's quite the best place to post. So, here is my pb : I have a csv file, with comma separator and text enclosed by ". First pb is with text in " ......... ", wich sometimes includes lines break, and commas And to complicate a little more,... (4 Replies)
Discussion started by: yogeek
4 Replies

9. Shell Programming and Scripting

How to change the line separator?

Hi All, I have a file with 20 columns, and the data itself has "\n" new line in it. So we have changed the row delimiter to ^E. Now i am unable to use head, wc -l etc... Please let me know how to change the line separator temporarily to run these unix commands. Thanks. (1 Reply)
Discussion started by: baranisachin
1 Replies

10. Shell Programming and Scripting

Valid separator in time and date format

Hello. I can use any particular (stupid or not) format when using bash date command. Example : ~> date --date "now" '+%Y-%m-%d %H!%M!%S' 2019-06-03 12!55!33or ~> date --date "now" '+%Y£%m£%d %H¤%M¤%S' 2019£06£03 12¤57¤36 or ~> date --date "now" '+%Y-%m-%d %H-%M-%S' 2019-06-03 12-58-51 ... (4 Replies)
Discussion started by: jcdole
4 Replies
FPRINTF(3)								 1								FPRINTF(3)

fprintf - Write a formatted string to a stream

SYNOPSIS
int fprintf (resource $handle, string $format, [mixed $args], [mixed $...]) DESCRIPTION
Write a string produced according to $format to the stream resource specified by $handle. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $format - See sprintf(3) for a description of $format. o $args - o $... - RETURN VALUES
Returns the length of the string written. EXAMPLES
Example #1 fprintf(3): zero-padded integers <?php if (!($fp = fopen('date.txt', 'w'))) { return; } fprintf($fp, "%04d-%02d-%02d", $year, $month, $day); // will write the formatted ISO date to date.txt ?> Example #2 fprintf(3): formatting currency <?php if (!($fp = fopen('currency.txt', 'w'))) { return; } $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; // echo $money will output "123.1"; $len = fprintf($fp, '%01.2f', $money); // will write "123.10" to currency.txt echo "wrote $len bytes to currency.txt"; // use the return value of fprintf to determine how many bytes we wrote ?> SEE ALSO
printf(3), sprintf(3), sscanf(3), fscanf(3), vsprintf(3), number_format(3). PHP Documentation Group FPRINTF(3)
All times are GMT -4. The time now is 08:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy