Quick awk tip :)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Quick awk tip :)
# 1  
Old 11-21-2012
Tools Quick awk tip :)

how do i "awk" the date after the from only to compare it on a if statement later .

filename example:
Code:
server1-ips-ultranoob-ok_From_2012_21_12-23:40:23_To_2012_21_12-23:49:45.zip


what i want o do is compare only the date from the string in "From_2012_21_12" in this case i only want the "2012_21_22"

and make the if comparison but i got that cover Smilie

Tnx guys .Smilie
# 2  
Old 11-21-2012
Code:
filename="server1-ips-ultranoob-ok_From_2012_21_12-23:40:23_To_2012_21_12-23:49:45.zip"
DT=$( echo $filename | awk -F"From_" ' { print substr($2,1,10) } ' )
echo $DT
2012_21_12

These 2 Users Gave Thanks to Yoda For This Post:
# 3  
Old 11-21-2012
well i must be doing something wrong ... lets see :

Code:
today_date =$(date +"%Y"_"%m"_"%d") # this returns ex: 2012_11_21

for i in  $(ls)
do
    if [ $(echo $i | awk -F"From_" ' { print substr($2,1,10) } ' ) eq $today_date]
    then
        mv $i $today_date
    else
       echo $i >> not_moved.txt
   fi
done

i try to put in the if echo "$i" == "$today_date" i get unary operator

Last edited by drd0spt; 11-21-2012 at 01:44 PM.. Reason: example of the error
# 4  
Old 11-21-2012
Corrections:-
Code:
today_date=$(date +"%Y"_"%m"_"%d") # this returns ex: 2012_11_21

for i in * # OR you can use *.zip
do
        if [ $( echo "$i" | awk -F"From_" ' { print substr($2,1,10) } ' ) = "$today_date" ]
        then
                mv "$i" "$today_date"
        else
                echo "$i" >> not_moved.txt
        fi
done

# 5  
Old 11-21-2012
today_date = is wrong.
today_date= is correct.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quick awk question

gawk 'BEGIN{count=0} /^Jan 5 04:33/,0 && /fail/ && /09x83377/ { count++ } END { print count }' /var/log/syslog what is wrong with this code? i want to search the strings "fail" and "09x83377" from all entries. im grabbing all entries in the log starting from Jan 5 04:33 to the end of the... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

Tip: alternative for NR==FNR in awk

Example: $ cat file1 2 3$ cat file2 1 2 3 4 5 6The following awk script works like a charm, NR==FNR is true for file1, the remainder runs for file2: awk ' NR==FNR {A; next} ($1 in A) ' file1 file2 2 3Now have an empty file1: >file1and run the awk script again. The result is empty... (8 Replies)
Discussion started by: MadeInGermany
8 Replies

3. Shell Programming and Scripting

awk :quick question removing empty line.

How to write in awk to remove lines starting with "#" and then process the file: This is not working: cat file|awk '{if ($0 ~ /^#/) $0="";print NF>0}' When I just give cat file|awk '{if ($0 ~ /^#/) $0="";print }' it prints the blank lines . I don't wnat the blank lines along with the... (15 Replies)
Discussion started by: rveri
15 Replies

4. Shell Programming and Scripting

awk Quick Help: printing upto 3rd octet .

Hi Experts, I am trying to print $2 & the IP_address upto 3rd octet only. But unable to do so, Trying # awk '{print $2, substr($4,1,9)}' file . but not correct File: HOST= cmiHOST06 :: 10.26.107.73:/data120 /nbu/cmiHOST06/athpx07/aa1 HOST= cmiHOST05 :: 10.26.12.76:/data120... (5 Replies)
Discussion started by: rveri
5 Replies

5. Shell Programming and Scripting

Quick sed/awk question

Hi fellow linux-ers, I have a quick question for you. I have the following text, which I would like to modify: 10 121E(121) 16 Jan 34S 132E 24 Feb 42 176E(176) 18 Sep 21S 164E 25 May 15 171W(-171) 09 Jul How can I do the following 2 modifications using sed and/or awk? 1. in 1st column,... (1 Reply)
Discussion started by: lucshi09
1 Replies

6. Shell Programming and Scripting

Quick help on 'awk' needed...!!

bash-2.05$ A=`cat /etc/group |awk -F':' '{if ($1$3$4 ==... (3 Replies)
Discussion started by: ak835
3 Replies

7. UNIX for Dummies Questions & Answers

Quick egrep / awk help, Please

Ok, this may be very simple but I can't find a solution. I have a list of numbered values which I have grepped from a larger life. ex/ 1:7.54 2:4.52 3:3.22 4:2.11 5:3.59 6:4.36 7:6.88 8:12.28 9:13.37 10:15.6 11:17.66 12:14.25 I need a quick way to organize them (using awk?)... (4 Replies)
Discussion started by: jdolny
4 Replies

8. Shell Programming and Scripting

Help with AWK -- quick question

Ok. I'm just starting to use AWK and I have a question. Here's what I'm trying to do: uname -n returns the following on my box: ftsdt-svsi20.si.sandbox.com I want to pipe this to an AWK statement and make it only print: svsi20 I tried: uname -n | awk '{ FS = "." ; print $1 }' ... (5 Replies)
Discussion started by: Probos
5 Replies

9. UNIX for Dummies Questions & Answers

quick check of my awk syntax

I've made an awk command that works successfully. However I'd like to add one character to it. For example instead of /what_i_have_now/ I'd like to change just ONE field to the opposite with an exclamation point. Like this: ! /what_i_have_now/ My question, where am I supposed to place... (1 Reply)
Discussion started by: yongho
1 Replies
Login or Register to Ask a Question