Awk variable in a separate file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk variable in a separate file
# 1  
Old 06-06-2012
Awk variable in a separate file

Hi all,

I have a requirement to put all the varibles used in an awk command in a separate file. This is because i have arround 100 variables used in an awk command. So i want to put all the variables used for the awk command in a separate file.

Please help me on this.

Thanks in adv.
# 2  
Old 06-06-2012
This is because i have arround 100 variables used in an awk command

show your awk command
# 3  
Old 06-06-2012
awk -F'|' 'BEGIN{a=1;b=2;c=3;d=4;e=5} {if($1=a){...} if($2=b){...}....}' < input_file

The command is like this...

I want to put all the variable used here like a,b,c,d,e in a separate file... and want to use here in the if statement of awk command...

Please let me know if there is any way for this...

Thanks..
# 4  
Old 06-06-2012
in the end of awk

Code:
 
awk -F'|' 'BEGIN{a=1;b=2;c=3;d=4;e=5} {if($1=a){...} if($2=b){...}....} {print a,b,c > "out.txt"}'

# 5  
Old 06-06-2012
Hi..

I need the input variables in an input file... like:-

a=1;b=2;c=3;d=4;e=5; -----> in an input file

This is because, i have more than 100 variables used here. And if in future i hv some modifications in the variables value, then no need to open the file and do the modification which have the awk command. just i can modify the input file having variables there...thats why I want to put all the input variables in a separate file.

So, please let me know is it possible...

thanks...
# 6  
Old 06-06-2012
what is the purpose ? and what kind of script you are doing ?

provide the input expected output
# 7  
Old 06-06-2012
i'm not clear about you want to which condition and input and desired?
but try something
Code:
# cat test
a=1;b=2;c=3;d=4;e=5
# awk -F';' '{for(i=1;i<=NF;i++){split($i,a,"=");if(a[2]==++xx)print a[1]"="a[2]>a[1]}}' test
# cat a
a=1
# cat b
b=2
# cat c
c=3
# cat d
d=4
# cat e
e=5

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tar with variable date in separate shell

Hi, I am trying to Zip a folder inside a shell script like below. It successfully taring but it only returns Null inside the variables. Searched a lot but no clue to finding the root cause. testno=1; date=20171128; DIR=/root/ sh -c 'cd $DIR; tar cvf "AWS.${testno.${date}.tar" "./AWS"' ... (5 Replies)
Discussion started by: pradyumnajpn10
5 Replies

2. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

Separate variable value

Friends, I have the following problem var=30|500; I need to keep those values in the variable other unique pattern that I have is | so should be var2=30; var3=500; I tried to use my split does not work Example failed var2=split("|",$var); var3=split("|",$var); (4 Replies)
Discussion started by: tricampeon81
4 Replies

4. Shell Programming and Scripting

Csv file separate using awk

Hi, I have file like below apple,orange,pineapple,pappya,guva,avocado want to store as apple orange pineapple pappya I tried below command to seprate first field command1: (3 Replies)
Discussion started by: stew
3 Replies

5. Shell Programming and Scripting

Need help with awk statement to break nth column in csv file into 3 separate columns

Hello Members, I have a csv file in the format below. Need help with awk statement to break nth column into 3 separate columns and export the changes to new file. input file --> file.csv cat file.csv|less "product/fruit/mango","location/asia/india","type/alphonso" need output in... (2 Replies)
Discussion started by: awk-admirer
2 Replies

6. Shell Programming and Scripting

awk print header as text from separate file with getline

I would like to print the output beginning with a header from a seperate file like this: awk 'BEGIN{FS="_";print ((getline < "header.txt")>0)} { if (! ($0 ~ /EL/ ) print }" input.txtWhat am i doing wrong? (4 Replies)
Discussion started by: sdf
4 Replies

7. Shell Programming and Scripting

awk/sed script to print each line to a separate named file

I have a large 3479 line .csv file, the content of which looks likes this: 1;0;177;170;Guadeloupe;x 2;127;171;179;Antigua and Barbuda;x 3;170;144;2;Umpqua;x 4;170;126;162;Coos Bay;x ... 1205;46;2;244;Unmak Island;x 1206;47;2;248;Yunaska Island;x 1207;0;2;240;north sea;x... (5 Replies)
Discussion started by: kalelovil
5 Replies

8. Shell Programming and Scripting

handling multiple files using awk command and wants to get separate out file for each

hai all I am new to the world of shell scripting I wanted to extract two columns from multiple files say around 25 files and i wanted to get the separate outfile for each input file tired using the following command to extract two columns from 25 files awk... (2 Replies)
Discussion started by: hema dhevi
2 Replies

9. Shell Programming and Scripting

Using AWK to separate data from a large XML file into multiple files

I have a 500 MB XML file from a FileMaker database export, it's formatted horribly (no line breaks at all). The node structure is basically <FMPXMLRESULT> <METADATA> <FIELD att="............." id="..."/> </METADATA> <RESULTSET FOUND="1763457"> <ROW att="....." etc="...."> ... (16 Replies)
Discussion started by: JRy
16 Replies

10. Shell Programming and Scripting

How to separate a variable

Hi, This is what happened after I came back from vacation: I don't remember how to do some simple things anymore. I have a variable being passed in Kshell script. I only know the variable is like string: "str1 str2 str3 ....", and they are separated with blank spaces. I need to separate each... (4 Replies)
Discussion started by: whatisthis
4 Replies
Login or Register to Ask a Question