nawk Wert einer Variablen zur 2. Spalte eines Files addieren


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nawk Wert einer Variablen zur 2. Spalte eines Files addieren
# 1  
Old 10-07-2008
nawk Wert einer Variablen zur 2. Spalte eines Files addieren

wie kann ich zu dem 2. wert eines files den wert einer variable hinzufügen bei nawk?

ich habe folgendes:

nawk '{system("echo "$1" "$2+22)}' filename

das funktioniert -> so wird beim zweiten wert 22 hinzugezählt!

ich möchte aber nicht 22 hinzufügen sondern den wert, der in der variablen itest steht! wie mache ich das?

so funktionierts nicht:

declare -i itest=22

nawk '{system("echo "$1" "$2+${itest})}' filename

wie geht es, dass ich zu jedem 2. wert des files den inhalt meiner variablen hinzufüge?
# 2  
Old 10-07-2008
I have following problem: when I use this command - it works fine:

nawk '{system("echo "$1" "$2+22)}' filename

but when I want to add to the second column of the file (filename) the content of the variable itest I get an error! how can I add the content of the variable itest to every value of the second column of the file?

the following doesnt work:

declare -i itest=22

nawk '{system("echo "$1" "$2+${itest})}' filename

can someone help me?
# 3  
Old 10-07-2008
Code:
nawk -v itest="22" '{print $1 " " $2+itest)}' filename

Regards
# 4  
Old 10-07-2008
it works after 4 hours without solution! Thank you for your help!
# 5  
Old 10-07-2008
I want to make a bash script and declare my variables at the beginning of my programm with all my commands!

#!/usr/bin/bash

declare -i inoargs=0
declare -i iusedpseudo=0
declare -r filestart="map"
declare -r fileend=".out"
declare -r command1="`/usr/bin/tail -1 $1${fileend} | awk '{print $2}'`"

while [ $# -gt ${inoargs} ]
do
iusedpseudo=0
# now file $1${fileend} will be created with: do something > $1${fileend}
iusedpseudo=${command1}
echo ${iusedpseudo}
shift
done


I get an error because when i declare command1 the file $1${fileend} does not exists! how can i solve this problem, that i can declare the command at the beginning of the script?
# 6  
Old 10-07-2008
Wenn du eine verschiedene Frage hast, geht es besser eine neue "Thread" zu anfangen...

Verändern bis so:
Code:
declare -r command1="/usr/bin/tail -1 $1${fileend} | awk '{print $2}'"
# keine "backtick"
...
...
iusedpseudo=`${command1}`
# steck die backticken hier ein.


Last edited by otheus; 10-07-2008 at 11:50 AM.. Reason: clarification
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

2. UNIX for Dummies Questions & Answers

Nawk 2 files

file 1 abcedef|wert|13|03|10|04|23|A1|13|05|01|09|31|9.516666667 fsdasdf|ferg|12|04|25|21|21|A1|13|02|26|20|31|20.51666667 dfsfsad|gerg|12|04|25|21|21|A1|13|02|25|25|31|4.166666667 wqeqwee|wewe|13|02|01|23|52|A1|13|05|01|09|31|9.516666667 file 2 abcedef|fsdsa|3000 fsdasdf|dasfa|3200... (9 Replies)
Discussion started by: radius
9 Replies

3. Shell Programming and Scripting

Merging two tab separated files via nawk

I searched a lot considering this theme,but still cant make my code working. I have two tab separated files, I want to do the following thing: File 1: xx1 y yy xx2 y yy xx3 y yy xx4 y yy File 2: xx1 z1 xx2 z2 xx3 z3 xx4 z4 xx5 z5 So I want to merge them ,according to... (9 Replies)
Discussion started by: divergenciya
9 Replies

4. Shell Programming and Scripting

ksh/nawk help with if statement to choose between 2 files

Hi! I am having a bit of a problem with my script. There are two different date formats that may appear in a file, either Jul-12 or Jul--6. I tried to create an if statement that searches for one of the formats and if that doesn't exist searches for the other, however it doesn't seem to be... (3 Replies)
Discussion started by: ther2000
3 Replies

5. Shell Programming and Scripting

match 2 files using nawk command

i am matching two files. the files are in the format file_1.txt 1|_|X|_| 2|_|W|_| 3|_|Y|_| 4|_|Z|_| 5|_|U|_| file_2.txt W|_|A|_| Z|_|C|_| V|_|B|_| X|_|D|_|sdff|_| Y|_| file_3.txt should be in the format (4 Replies)
Discussion started by: centurion_13
4 Replies

6. Shell Programming and Scripting

Nesting - two nawk into one nawk

hi people; this is my two awk code: nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies

7. Shell Programming and Scripting

Backup eines Verzeichnis und der unterverzeichnisse erstellen

Hallo ich bin neu in dem bereich Bash scripting und deswegen suche ich ein script der auf meinem unix server laufen soll und zwar immer wenn ich den server starte oder alle 24h der script soll ein backup von einem verzeichnis und meheren unterverzeichnissen erstellen da ich nirgends was... (1 Reply)
Discussion started by: HansWurst
1 Replies

8. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

9. Shell Programming and Scripting

Using NAWK to merge two files

Two files need to be joined on a second column. File 1 FRO FRONTIER MWC MIDWEST ORB ORBITZ ATR AIRTRAN BWI BESTWESTERN File 2 M AIRTRAN 8 TRIPS_YTD A M BESTWESTERN 8 ... (7 Replies)
Discussion started by: madhunk
7 Replies
Login or Register to Ask a Question