a cut-command or special format pattern in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting a cut-command or special format pattern in awk
# 1  
Old 08-06-2012
a cut-command or special format pattern in awk

Hi

i read data with awk,
Code:
01.07.2012	00:10	227.72	247.50	1.227	1.727	17.273
01.07.2012	00:20	237.12	221.19	2.108	2.548	17.367
01.07.2012	00:30	230.38	230.34	3.216	3.755	17.412
01.07.2012	00:40	243.18	242.91	4.662	5.172	17.328
01.07.2012	00:50	245.58	245.41	5.179	5.721	17.128
01.07.2012	01:00	256.63	253.30	5.002	5.711	16.980
01.07.2012	01:10	263.29	257.95	5.208	5.860	16.746
01.07.2012	01:20	262.18	258.82	5.529	6.091	16.477

and i want to achieve an output, especially for the timestamp 07/01/12-hh:mm
Code:
...
awk '{printf("%02d/%02d/%2d-%02d:%02d\t%.2f\t%.2f\t%.3f\t%.3f\t%.3f\n",$2,$3,$1,$4,$5,$6,$7,$9,$10,$11)}' OFS='\t' $home/data.dat > $home/out.txt

Is there an parameter for awk '{printf( , where i can set the pattern for two-number-year?

Thanks in advance!
IMPe
# 2  
Old 08-06-2012
Code:
echo "2012" | awk '{printf "%02d\n", substr($0,2)}'
12

# 3  
Old 08-06-2012
Quote:
Originally Posted by in2nix4life
Code:
echo "2012" | awk '{printf "%02d\n", substr($0,2)}'
12

THANK YOU, it is working properly!
# 4  
Old 08-06-2012
Code:
awk '{split($1,a,".");$1=a[1]"/"a[2]"/"a[3]%100"-"$2;$2=""}1' OFS='\t' myFile

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 format each line by pattern

The four lines in the tab-delimeted input are a sample format from my actual data. The awk is meant to go line by line and check if a pattern is satisfied and if it is follow a particular format (there are 3). All the lines in the file should follow one of the three formats below. I added comments... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

3. Shell Programming and Scripting

Help with cut or awk command

i am trying to cut the 4th field from the file. sample file a1,a2,"a,3",a4,a5,a6 b1,"b,2",b3,b4,b5,b6 c1,"c,2","c,3",c4,c5,c6 i need the output in the format of a1,a2,"a,3",a5,a6 b1,"b,2",b3,b5,b6 c1,"c,2","c,3",c5,c6 i tried using cut -d, -f1-4,6- but i am getting the output as ... (10 Replies)
Discussion started by: ATWC
10 Replies

4. Shell Programming and Scripting

awk and cut command

Hi, I have to display the value 16 present in "lcpu=16" which is the output of a command # vmstat System configuration: lcpu=16 mem=4096MB I used as # hdtype=`vmstat | grep "lcpu" | awk -F "=" '{print $2}'` # echo $hdtype 16 mem But I need to display only 16.. Am doing... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

5. Shell Programming and Scripting

AWK command to cut the desired header columns

Hi Friends, I have a file1 i want to retrieve only the fields which have DEP,CITY,TRANS as headers in other file. Output: I want to give the input as DEP,CITY,TRANS column names to get the output. i used cut command .. but if i have 300 fileds it is more difficult to... (4 Replies)
Discussion started by: i150371485
4 Replies

6. UNIX for Dummies Questions & Answers

Regarding cut or awk command

Hi, I need a help with cut/awk command. I need to get certain values from a string provided. For example: i have a config file with below mentioned details oracle="user=name"/"pass/word"@databasename. I have used a command var1=`grep -w oracle sample.cfg | cut -d"=" -f2 | cut -d"/" -f1`. ... (10 Replies)
Discussion started by: kumars2102
10 Replies

7. UNIX for Advanced & Expert Users

awk command in special character

Hi, I want to add below line after end of a file (i.e file1) &&echo "copy done" >> out.txt cat file1 scp user1@server1:/tmp/dir /tmp/dir1 my requirment is cat file1 scp user1@server1:/tmp/dir /tmp/dir1 &&echo "copy done" >> out.txt could any one please help me (7 Replies)
Discussion started by: anshu ranjan
7 Replies

8. Shell Programming and Scripting

Sed or awk : pattern selection based on special characters

Hello All, I am here again scratching my head on pattern selection with special characters. I have a large file having around 200 entries and i have to select a single line based on a pattern. I am able to do that: Code: cat mytest.txt | awk -F: '/myregex/ { print $2}' ... (6 Replies)
Discussion started by: usha rao
6 Replies

9. Shell Programming and Scripting

awk search pattern with special characters passed from CL

I'm very new to awk and sed and I've been struggling with this for a while. I'm trying to search a file for a string with special characters and this string is a command line argument to a simple script. ./myscript "searchpattern" file #!/bin/sh awk "/$1/" $2 > dupelistfilter.txt sed... (6 Replies)
Discussion started by: cue
6 Replies

10. Shell Programming and Scripting

awk,cut fields by change field format

Hi Everyone, # cat 1.txt 1321631,77770132976455,19,20091001011859,20091001011907 1321631,77770132976455,19,20091001011859,20091001011907 1321631,77770132976455,19,20091001011859,20091001011907 # cat 1.txt | awk -F, '{OFS=",";print $1,$3,$4,$5}' 1321631,19,20091001011859,20091001011907... (7 Replies)
Discussion started by: jimmy_y
7 Replies
Login or Register to Ask a Question