AWK with allow me to add spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK with allow me to add spaces
# 1  
Old 03-07-2008
Bug AWK with allow me to add spaces

I have a file like this:
running:running since Mon Mar 3 09:46:19 2008:
running:running since Thu Mar 6 22:36:51 2008:
running:running since Tue Dec 4 00:34:15 2007:
running:running since Tue Dec 4 00:34:16 2007:
running:running since Mon Jan 21 11:15:04 2008:
running:running since Mon Jan 21 11:15:12 2008:

This is a log file, it creates everyday some log. I want to search for the specific day of yesterday.

date | awk '{ print $2 , $3-1}'

The answer will be: Mar 6

This awk has the a problem with this. If you see in my log file, "Mar" is 2 spaces from 6, not one like the awk show. How can i add one space to this file, I tried with "\t" but it does not work like i need.

Rbulus
# 2  
Old 03-07-2008
Quote:
Originally Posted by rbulus
I have a file like this:
running:running since Mon Mar 3 09:46:19 2008:
running:running since Thu Mar 6 22:36:51 2008:
running:running since Tue Dec 4 00:34:15 2007:
running:running since Tue Dec 4 00:34:16 2007:
running:running since Mon Jan 21 11:15:04 2008:
running:running since Mon Jan 21 11:15:12 2008:

This is a log file, it creates everyday some log. I want to search for the specific day of yesterday.

date | awk '{ print $2 , $3-1}'

The answer will be: Mar 6

This awk has the a problem with this. If you see in my log file, "Mar" is 2 spaces from 6, not one like the awk show. How can i add one space to this file, I tried with "\t" but it does not work like i need.

Rbulus
Code:

date | awk '{ print $2" ", $3-1}'
# 3  
Old 03-07-2008
How will the awk handle Apr 1 as it will display Apr 0 instead of Mar 31?
# 4  
Old 03-08-2008
if you have GNU date
Code:
# d=$(date +"%b%_d" -d "1 day ago")
# grep "$d" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Add spaces to variable

Hi, I'm passing a variable to a scrpit which can be 1 to 3 characters long. How can I force it to be three character long and add spaces to it? The passed variable is stored in $1 and I would like to be stored in NewName I tried without success NewName=$(printf "%*s 3 $1) So if... (2 Replies)
Discussion started by: f_o_555
2 Replies

2. UNIX for Dummies Questions & Answers

Want to add trailing spaces to the variable

I want to keep string/varible length to 10 even its actual length is less than 10(may be no value). so, i want to add trailing spaces to my string. :wall: "typeset -L10 myvarible" is not working, its saying invalid typset -L option. Can you please advise. (4 Replies)
Discussion started by: djaks111
4 Replies

3. Shell Programming and Scripting

Add spaces when x-coordinate changes with Awk

I have a tab-delimited file with three columns. They are arranged in blocks like this 1 1 8 1 2 3 1 3 7 1 4 4 1 5 7 2 1 9 2 2 4 ... I would like to add spaces so that the file looks like this: 1 1 8 1 2 3 1 3 7 1 4 4 1 5 7 (3 Replies)
Discussion started by: machinus
3 Replies

4. Shell Programming and Scripting

awk for removing spaces

HI, I have a file with lot of blank lines, how can I remove those using awk?? Thanks, Shruthi (4 Replies)
Discussion started by: shruthidwh
4 Replies

5. Shell Programming and Scripting

awk and spaces in filenames

Hey there, this is my first post and I'll try to explain my situation as best I can.Here is a sample of the input file: ADO Sample.h,v ADO Sample 2010-05-21 lyonsb /repository/patents/TSCommon/OpenSource/Dundass/ug6mfc/DataSources/Ado/ADO Sample ADO SampleDoc.h,v ADO SampleDoc 2010-05-21... (3 Replies)
Discussion started by: rodan90
3 Replies

6. Shell Programming and Scripting

add semicolumn and remove spaces

Hi I have a file like: one two three four five six seven eight nine ten and I'd like to get one:two:three:four:five I'm trying to do it with sed, but the problem is also that the spaces between the words are not constant. Any idea please? thanks ... (5 Replies)
Discussion started by: Dedalus
5 Replies

7. UNIX for Dummies Questions & Answers

VIM add white spaces

Hello, How do I adda two whitespaces at the begining of each lines between line 12 and line 90; something like :12,90 ??? Thanks! (3 Replies)
Discussion started by: JCR
3 Replies

8. Shell Programming and Scripting

can v add 'n' of spaces by a single command?

Hi All, I just need to check for 'tabs' in my input file and need to replace all tabs into 'n' no. of spaces. Say for example if I give NO_OF_SPACE=5, then it should replace all tabs with 5 spaces abc.in ##### asdasdasd \t\t\tasjkalskdl;asdsdjfksldfjklsdfxcmxm,cv... (2 Replies)
Discussion started by: askumarece
2 Replies

9. Shell Programming and Scripting

Help with awk adding spaces.

I have a file that contains... elm,mail elm,lisp,composer,cd,ls,cd,ls,cd,ls,zcat,|,tar,-xvf,ls,cd,ls,cd,ls,vi,ls,cd,ls,vi,elm,-f,ls,rm,ls,cd,ls,vi,vi,ls,vi,ls,cd,ls,elm,cd,ls,cd,ls,vi,vi,vi,ls,vi,ls,i,vi,ls,cp,cd,fg,ls,rm,cd,ls,-l,exit elm,mail,biff,elm,biff,elm,elm elm,ls ... (2 Replies)
Discussion started by: Bandit390
2 Replies

10. Shell Programming and Scripting

Add spaces between Characters

I need to add spaces in between characters in a string variable. Is there a shortcut? I know you can remove the spaces with sed, but does sed have a way to add them? Example: I have: DATA01 I want it to be: D A T A 0 1 What I have done so far is to create a function... (4 Replies)
Discussion started by: heyindy06
4 Replies
Login or Register to Ask a Question