Some problem with awk or sed in if conditions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Some problem with awk or sed in if conditions
# 1  
Old 12-24-2012
Some problem with awk or sed in if conditions

Code:
Code:
#set -x
path=`pwd`
while read line
do
dd=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $2}'`
if [ `date +%d` -eq $dd ]
then
mm=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $1}'`
yy=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $3}'`
var=`echo $line|awk -F"," '{print $2}'`
var1=`echo $line|awk -F"," '{print $3}'`
find $path -name "$var-SUBS.csv"
echo "wget $var-SUBS.csv & $var-$var1-$dd$mm$yy"
sed 's/\$line/\$line\$var\-\$var1-\$dd\$mm\$yy/g' 1.txt
#awk "{ print $0 "$var-$var1-$dd$mm$yy" }" 1.txt
fi
done < 1.txt



1.txt contains

12/21/2012,EN,LE
12/21/2012,EN,GK
12/21/2012,KN,LE
12/24/2012,AS,LE
12/26/2012,MH,RH
12/29/2012,HN,LE
12/27/2012,AS,LE
12/30/2012,KN,LE
12/25/2012,KN,GK
12/24/2012,KL,LE
1/7/2013,GA,LE
1/8/2013,TN,LE
1/9/2013,AP,GK
1/4/2013,HP,LE
1/5/2013,MP,LE
1/6/2013,JK,RH


required format is


12/21/2012,EN,LE
12/21/2012,EN,GK
12/21/2012,KN,LE
12/24/2012,AS,LE,KL-LE-24122012
12/26/2012,MH,RH
12/29/2012,HN,LE
12/27/2012,AS,LE
12/30/2012,KN,LE
12/25/2012,KN,GK
12/24/2012,KL,LE,KL-LE-24122012
1/7/2013,GA,LE
1/8/2013,TN,LE
1/9/2013,AP,GK
1/4/2013,HP,LE
1/5/2013,MP,LE
1/6/2013,JK,RH

PS: only for the current date i want the 4th column....
# 2  
Old 12-24-2012
Code:
DT=$( date +"%m/%d/%Y" )
FD=$( date +"%d%m%Y" )

awk -F, -v dt=$DT -v fd=$FD '$1==dt { print $0","$2"-"$3"-"fd; } $1!=dt { print $0; } ' 1.txt

This User Gave Thanks to Yoda For This Post:
# 3  
Old 12-24-2012
Code:
# echo $dat
12/24/2012

# echo $var
AS

# echo $var1
LE

# grep "$dat" 1.txt | sed "s/$/",$var-$var1-$(date +%d%m%Y)"/"
12/24/2012,AS,LE,AS-LE-24122012

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to delete one regular pattern with conditions

Hi All , I am having a file like this INPUT FILE ############################### addfd_mjlala kksks sksks ks annsns_bbox_2 (sksksk ksks ) adnndn_nsns_bbox_3 (( jsjsdj sjsj ) malm_dkdm lsls lsl mdndk_mkmd_dkd_bbox_4_kdkd ksksk skksk_bbox_jsj_KSK ((jsjsj jsjsj )... (2 Replies)
Discussion started by: kshitij
2 Replies

2. Shell Programming and Scripting

Using sed and if multiple conditions

Hi I've been trying to get this to work but so far no luck. #!/usr/bin/ksh unset EXP APP=$1 EXP=`sed -n "/${APP}/p" tIclrpt.out |awk '{print $7}'|sed '/^$/d'` EXT=`sed -n "/${i}/p" ${SESLOG} |awk '{print $4}'|grep "${i}"` EXEM=/path/to/fail ACTI=/path/to/success if || then... (10 Replies)
Discussion started by: techy1
10 Replies

3. Shell Programming and Scripting

Problem with output awk and sed

I have file, i am extracting email address from file. but problem is that output is very ugly. I am using this command REMOVED "CSS OFFENDING CODE"... While original filename have no such character. Please suggest. (20 Replies)
Discussion started by: learnbash
20 Replies

4. Shell Programming and Scripting

awk problems - awk ignores conditions

awk 'BEGIN{ if('"$CATE"'<'"${WARN}"') printf ("%s", "'"`Kfunc "" ; break`"'") else if (('"${CATE}"'>='"${WARN}"') && ('"${CATE}"'<'"${CRIT}"')) printf ("%s", "'"`Wfunc ""; break`"'") else if ('"${CATE}"'>='"${CRIT}"') printf... (6 Replies)
Discussion started by: SkySmart
6 Replies

5. Shell Programming and Scripting

awk/sed problem

I have a bunch of files I need to change a letter to another letter only in the first column of a space delimited file. The problem is that after the first column, there's comments and such that cause problems with awk. Here's what my data looks like: 16a28.0a27.0a26.0a25.0a24.67.255.200... (3 Replies)
Discussion started by: supradave
3 Replies

6. Shell Programming and Scripting

awk and sed problem

Hi, I am able to generate a csv file which has 3 columns. But the header is not coming out exactly i.e it doesnot have a comma in between it but the data is getting produced with the comma. The first line i.e the header is coming out as:- Counter Number Counterparty1 Counterparty2 ... (10 Replies)
Discussion started by: scripter12
10 Replies

7. Shell Programming and Scripting

if, sed or awk with conditions

I do not know how to do this unless I use a bunch of if statements. I need a script to replace numbers in each record in a file. I am really getting tangled in this web. If a fieldA (19 positions) is greater than 14 digits, I have to change the data (resulting fieldA is fixed 19 postions). If... (5 Replies)
Discussion started by: ski
5 Replies

8. Shell Programming and Scripting

problem with if, while, for conditions

Hi All, when iam running the script with if or while it showing following erros Please any one clarify this my script is: ------------ cat fileList.txt | while read line do echo $line done output: -------- searchGateway.sh: line 14: syntax error near unexpected token `done'... (3 Replies)
Discussion started by: kittusri9
3 Replies

9. Shell Programming and Scripting

awk...sed problem

Hi guys, I am tryingto delete or ignore columns in a large dataset using 'sed'. For example, I have the following dataset: - 20060714,X.XX,1,043004,Q,T,24.0000,1,25.5000,4, 20060714,X.XX,1,081209,Q,T,24.0000,1,25.5000,5, As you can see, there are 10 columns here and the table that I am... (1 Reply)
Discussion started by: aarif
1 Replies

10. UNIX for Dummies Questions & Answers

sed/awk String problem

I would appreciate it if any one can guide me in using awk perhaps sed in extracting some values from a long string. here is an example. .......some lines here........ ........ aaaa bbbb cccc ddddd eeeee fffff gggg (time:hhhh)........ ......some lines here also.......... How can I extract... (2 Replies)
Discussion started by: odogbolu98
2 Replies
Login or Register to Ask a Question