awk : combine 3 variables into 1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk : combine 3 variables into 1
# 1  
Old 12-16-2008
Question awk : combine 3 variables into 1

Within one of my awk scripts, I have three variables extracted and calculated on. When done, I simply want to combine the three. The following works, but looks weird. My script reads a field that has text and numbers, knowing the last four comprise MMYY (month and year)

Code:
# YY are last two digits; MM are two previous
   dtYY=substr(date_raw,length(date_raw)-1,2)
   dtMM=substr(date_raw,length(date_raw)-3,2)
# CC is for century; assume 90 as breakpoint meaning 1990 while 89 equals 2089
   if ( dtYY >= 90) dtCC=19
      else dtcc=20

   dtCCYYMM=dtCC""dtYY""dtMM

The above last line is the command line in question -- what else can I do to separate the three fields as I combine into one?
# 2  
Old 12-16-2008
you need nothing:
Code:
dtCCYYMM=dtCC dtYY dtMM

and you probably meant:
Code:
else dtCC=20

# 3  
Old 12-16-2008
Hammer & Screwdriver You are correct with both

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine two awk commands

Hi, Can someone please guide me how to combine the following two awk calls in one? I noticed that it is very often situation for me, and I think that it can be replaced with one awk call. The question is more general, not the exact one. echo "A B C/D" | awk '{print $3}' | awk -F/ '{print... (4 Replies)
Discussion started by: mirusnet
4 Replies

2. Shell Programming and Scripting

Combine awk commands into one

my code: gawk 'NR>'"${LASTLINENUM}"' && NR<='"${LINEENDNUM}"'' ${LOGFILE} | gawk '{l=$0;} /'"${STRING1}"'/ && /'"${STRING2}"'/ {for (i=NR-'"${BEFOREGLAF}"'; i<=NR+'"${AFTERGLAF}"'; i++) o=i; t++;} END { for(i=1; i<=NR; i++) if (o) print l; print t+=0;}' i would like to combine this into one... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. UNIX for Dummies Questions & Answers

Combine two lists of variables

Thanks in advance for any advice and help. I have two lists of variables that I want to put into nested for loops. for x in 1 2 3 do for y in a b c do The output I want is: filepath/1/ command modified by a filepath/2/ command modified by b filepath/3/ command modified by c To... (10 Replies)
Discussion started by: wheyhamp
10 Replies

4. Shell Programming and Scripting

Combine awk statement into one

awk '{a=$0} END {while (NR) print a}' mail.log | awk '/Feb 2/ {print ;exit;}' first, can this code be combined into one? what i want this code to do is output every single line it finds up until the last occurrence of "Feb 2". right now, this code simply outputs one line, and aborts. ... (12 Replies)
Discussion started by: SkySmart
12 Replies

5. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

6. Shell Programming and Scripting

Combine these two into one liner awk?

ignore the simplicity of the foo file, my actual file is much more hardcore but this should give you the jist of it. need to combine the two awks into one liner. essentially, need to return the value of one particular field in a file that has multiple comma separated fields. thanks guys cat foo... (1 Reply)
Discussion started by: jack.bauer
1 Replies

7. Shell Programming and Scripting

guide needed to combine 2 variables

readNOW=$(date +"%Y%m%d%H%M") read readTerminal #input B terminalc=$readTerminal echo eqpt_list_QC_$terminalcT_$readNOW how to get display result it: eqpt_list_QC_BT_201209121530 (2 Replies)
Discussion started by: ment0smintz
2 Replies

8. Shell Programming and Scripting

combine awk and tr -d

Hi Everyone, awk 'BEGIN{print strftime("%c",1272814948)}' | tr -d '\n' how to change tr -d '\n' to be part of the awk? means awk this pchoh time, and awk also remove '\n', instead of using "|" to combine "tr" command. Thanks (2 Replies)
Discussion started by: jimmy_y
2 Replies

9. Shell Programming and Scripting

Combine awk statements

I have an awk statement that works but I am calling awk twice and I know there has to be a way to combine the two statements into one. The purpose is to pull out just the ip address from loopback1. cat config.txt | nawk 'BEGIN {FS="\n"}{RS="!"}{if ( $0 ~ "interface loopback1" ) print$4}' | nawk... (5 Replies)
Discussion started by: numele
5 Replies

10. Shell Programming and Scripting

combine variables in one

Within one of my scripts, I have variables extracted from parameters list and want to combine some of them in one (lpath). I tried using awk command..... How do I get it? Thank you. #!/bin/bash # ## Read paramlist.txt file='/name1/name2/paramlist.txt' while read line do # key= echo... (4 Replies)
Discussion started by: Lenora2009
4 Replies
Login or Register to Ask a Question