awk, splitting date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk, splitting date
# 1  
Old 03-21-2011
awk, splitting date

can any1 explain me hw is below wrking:
wat is substr and dd,mmyear used for
wat values will go in dese?

Code:
sdt='31122010235959' 
 
sdate=`validate_date $sdt`
 
validate_date()
{
 dt="$1"
 set `echo $dt | nawk '{ print substr($0,1,2),substr($0,3,2),substr($0,5,4),substr($0,9,2),substr($0,11,2),subs:otr($0,13,2)}'`
 dd=`echo $1 | sed -e "s/^0//"`
 mm=$2
 year=$3
 hh=$4
 mi=$5
 ss=$6
echo "${3}${2}${1}${4}${5}${6}"
}


Last edited by pludi; 03-21-2011 at 07:01 AM..
# 2  
Old 03-21-2011
An explanation of the substr function:

Awk - A Tutorial and Introduction - The Substr function
# 3  
Old 03-21-2011
It could be shorten with something like

Code:
# echo "$sdt"
31122010235959
# echo "$sdt" | sed 's/\(..\)\(..\)\(....\)\(.*\)/\3\2\1\4/'
20101231235959

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Splitting week start date and end date based on custom period start dates

Below are my custom period start and end dates based on a calender, these dates are placed in a file, for each period i need to split into three weeks for each period row, example is given below. Could you please help out to achieve solution through shell script.. File content: ... (2 Replies)
Discussion started by: nani2019
2 Replies

2. Shell Programming and Scripting

awk to perform splitting

Dear all, In my working directory I have two files as: $ ls -ltr -rw-r--r-- 1 emily af-cms 7 30. Jul 09:56 L1File1_000_981.root -rw-r--r-- 1 emily af-cms 10 30. Jul 09:56 L1File2_000_980.root I want to have the OutputFile.txt with the following content: L1File1_000_981.root... (6 Replies)
Discussion started by: emily
6 Replies

3. Shell Programming and Scripting

Splitting a large file as per date

Hi, I need a suggestion for an issue in UNIX file. I have a log file in my system where data is appending everyday and as a consequence the file is increasing heavily everyday. Now I need a logic to split this file daily basis and remove the files more than 15 days. Request you to... (3 Replies)
Discussion started by: bhaski2012
3 Replies

4. Shell Programming and Scripting

Splitting the Data using awk

Hello All, I have a comma delimiter file with 10 columns. I took the desired data but from $4 I need to split into two columns as 3+7 bytes. awk -F"," -v OFS=',' '{print $2,$3,$4}' foo.txt 42366,11/10/2014,5012418769 42366,11/10/2014,2046955672 42366,11/10/2014,2076802951 ... (3 Replies)
Discussion started by: karumudi7
3 Replies

5. Shell Programming and Scripting

awk Splitting strings

Hi All, There is a file with a data. If the line is longer than 'n', we splitting the line on the parts and print them. Each of the parts is less than or equal 'n'. For example: n = 2; "ABCDEFGHIJK" -> length 11 Results: "AB" "CD" EF" GH" "IJ" "K" Code, but there are some errors.... (9 Replies)
Discussion started by: booyaka
9 Replies

6. Shell Programming and Scripting

Splitting the file using awk

Hi, I have a requirement in which I am going to receive one file and should be splitted to 9 different files based on one distinguisher called TYPE. I heard that this can be done using awk or sed. Can any one advise regardint the logic and simpler way other than using awk or sed is also... (15 Replies)
Discussion started by: sagar.cumar
15 Replies

7. Shell Programming and Scripting

Splitting file using awk

I have file with below content FG1620000|20000 FG1623000|23000 FG1625000|25000 FG1643894|43894 FG1643895|43895 FG1643896|43896 FG1643897|43897 FG1643898|43898 My aim is to split the above file into two files based on the value in the second field. If the value in second field is... (2 Replies)
Discussion started by: anijan
2 Replies

8. Shell Programming and Scripting

Splitting string with awk

Input: Debris Linux is a minimalist, desktop-oriented distribution and live CD based on Ubuntu. It includes the GNOME desktop and a small set of popular desktop applications, such as GNOME Office, Firefox web browser, Pidgin instant messenger, and ufw firewall manager. Debris Linux ships... (5 Replies)
Discussion started by: cola
5 Replies

9. UNIX for Dummies Questions & Answers

Record splitting with AWK

Hi all ! I need your help as quick as possible. My input file like this: bạc těnh ( 薄情) 1 . 薄情な.2. 夫婦或いは男女の不貞を指す。 bách (百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ)・ 3.圧迫する.4.差し迫った, My propose is take the value in the firt bracket. I used the command like : ...if (index(... (6 Replies)
Discussion started by: maixu134
6 Replies

10. Shell Programming and Scripting

Splitting a string with awk

Hi all, I want to split a string in awk and treat each component seperatley. I know i can use: split ("hi all", a, " ") to put each delimited component into array a. However when i want to do this with just a string of chars it does not work split ("hi", a, ""); print a; prints... (6 Replies)
Discussion started by: pxy2d1
6 Replies
Login or Register to Ask a Question