I need a suggestion, please help. I have a input file as below :
abc.txt :
I am using a perl script as below :
The above input file (abc.txt) that I have mentioned is an example file (since the original file will have upto 5 million records after the line : Kitnb/ICCID1/ICCID2/IMSI1/IMSI2/MSISDN1/MSISDN2/VOUCHER1/VOUCHER2)
Initially we had an perl script where we were validating each line by loading in array and running foreach for every line, after the below line in the input file (abc.txt): Kitnb/ICCID1/ICCID2/IMSI1/IMSI2/MSISDN1/MSISDN2/VOUCHER1/VOUCHER2
with an appropriate Regex as shown in the above perl script and we really faced performance issues. So, I was advised to use awk (though I see that it actually uses a new shell) for increase in performance, please suggest if you think otherwise. I have to use a perl script for few rules in organization.
Now, please suggest in the above script, how do i use the variable $test as input for the awk command ( i.e. $test2 = `awk 'BEGIN { count=0;} { if(/^([0-9])*,([0-9])*,([0-9])*,([0-9])*,([0-9])*,([0-9])*,([0-9])*,([0-9])*,\$/) count++; else print "Unmatching line" ; print } END { print "Number of Lines = ",count;}' abc.txt` since I want to process (run regex) the file for the regex only after the line as below (and not before it) : Kitnb/ICCID1/ICCID2/IMSI1/IMSI2/MSISDN1/MSISDN2/VOUCHER1/VOUCHER2
Running the awk as above will even process the above line and before it.
In short, how can I validate for Regex using a variable ($test1) as input to awk command and store the same in $test2.
If you have any other suggestion apart from the above, kindly let me know.
Thank you
Last edited by jim mcnamara; 12-04-2011 at 09:31 AM..
Reason: code tags please
I think your perl script should be like this (note the bold line).
Quote:
The above input file (abc.txt) that I have mentioned is an example file (since the original file will have upto 5 million records after the line : Kitnb/ICCID1/ICCID2/IMSI1/IMSI2/MSISDN1/MSISDN2/VOUCHER1/VOUCHER2)
Initially we had an perl script where we were validating each line by loading in array and running foreach for every line, after the below line in the input file (abc.txt): Kitnb/ICCID1/ICCID2/IMSI1/IMSI2/MSISDN1/MSISDN2/VOUCHER1/VOUCHER2
with an appropriate Regex as shown in the above perl script and we really faced performance issues. So, I was advised to use awk (though I see that it actually uses a new shell) for increase in performance, please suggest if you think otherwise. I have to use a perl script for few rules in organization.
Using the above code you've provided, you are using awk twice to parse the same data and that is the reason being slow. Instead, you could just use one awk command and parse the data and count the number of lines starting from a match of the following line
I think this is something you want to achieve? If that's the case, then you could either use awk or perl to accomplish.
Quote:
In short, how can I validate for Regex using a variable ($test1) as input to awk command and store the same in $test2.
To answer your original question and use the original code given, you could change it this way
For the below Suggestion I got the error as below.
=> perl Regex.pl
So, I modified the script as below (implementing the suggestion of using the variable) and it worked fine:
$test1 = `awk '/Kitnb\\/ICCID1\\/ICCID2/{f=1;next}f' 10k.txt | awk 'BEGIN { count=0;} { if('"$regex"') count++; else print "Correct the output file, The line is :" ; print ;} END {} '`;
Thank you MR.bean
Thanks,
Arun
---------- Post updated at 04:14 PM ---------- Previous update was at 04:13 PM ----------
BTW, could you please suggest why I got below error :
=> perl Regex.pl
Thanks,
Arun
Last edited by Scott; 12-05-2011 at 06:48 AM..
Reason: Code tags, please...
cat filename| awk '{ $1=""; print $0}'
in my file there are few lines that has more than 3000 characters per line and as soon as I run the above command it cores, strings core reveals that the awk is failing because input string too long, limit. can i get some help from the experts to find... (8 Replies)
Hi guys,
I wrote the following function to compare two csv files column by column.
However, sometimes the input needs to be sorted before parsing it to awk.
I can do this by changing the awk arguments, but I would like to make this variable if possible. The below doesn't work since the... (3 Replies)
HI,
MY question is a very simple one:
if i want to call an awk script with the input file name and also pass a variable value , then how to do it.
#>awk -f my_script.awk -v variable=value my_inputfile.txt
I can't do it like this.
throws error:
awk: my_script.awk:18:... (0 Replies)
Hi,
I would like to compare 2 files using awk, which I can do by using:
awk 'NR==FNR{a;next} (NR > 32 && $2 in a) {print $0}' File1 and File2.
If the name of the File1 is in another file (for example, column 4 in File 3) then how can I pass this column 4 to the awk command.
Thanks in... (1 Reply)
Hi everyone,
Can anyone tell me how to take contents of a variable as a pattern for awk command. Am doing as below, but doesnt get any output:
$c = "Tue Dec";
$log = ` awk '/ \$c /' in.txt`;
print $log; (7 Replies)
Hi guys,
Does awk have a built-in variable which I can use to display the input file it's currently reading?
I'm currently concatenating multiple files using awk and later on do some parsing. But for now, I want to add an extra column in the main output data file - basically putting in the... (3 Replies)
i have a requirement to compare two time stamps in IF condition and return true whenever the second timestamp is greater than first, i will also be checking, if the timestamp in HHMMSS format( 6 digit time stamp ).Im able to achieve it using awk, however i dont want to give any input file to awk... (3 Replies)
i have this script that reads a file "listall_101111" where 101111 varies.
awk '{print $0,$1}' listall_101111 | sed -e 's/\(.*\).$/\1/g' | awk '{print $6,$2,$3,$4,$5}' | sort -nrk5 | nawk 'NR==1{m=$5;a++;b=(b)?b:$0;next}$5==m{a++;b=(b)?b:$0}END{for (i in a){print b,a}}' | grep -v ^LG | sort... (4 Replies)
Hi
I am trying to edit a csv file. Bacically I need to input a search variable and the value that must be changed in one of the fields corresponding to that searched variable.
My csv file looks like so:
1,1A,5
1,1B,2
1,1C,3
2,2A,7
2,2B,4
2,2C,0
3,3A,1
3,3B,6
3,3C,4
I want to... (4 Replies)
Hi all,
I have a problem with qwk command.
i have to check process status and for that i am using command
prstat -mvL 1 1
and it gives me the entire output
but when i use this command with awk like this:
prstat -mvL 1 1 | awk -F" " '{print $1,$15}'
to get first and 15th arguments.
... (3 Replies)