Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding awk command to replace grep command

Status
Not open for further replies.

erche

Technical User
Aug 13, 2003
15
ID

Hello,
I have this command on someone's script :

grep "^[13];psf\/210;" $filen | cut -d";" -f$List >> ${pathOut}/psf_210_${dateFile}.txt

The 'List' created with awk :

List=$(nawk 'BEGIN { printf(&quot;1,2,3,4,5&quot;); for(i=9; i<=2231; i+=202) {
printf(&quot;,%d,%d,%d,%d&quot;,i+4,i+6,i+18,i+20) } }')

How to represent the grep command above with awk ?
I need it because that command should be modified, because the List now not only one, but I still need to have the same output.

I want to have the grep in one condition take the 1stList and another condition take the 2ndList but have to written to the same file output.

I hope that's clear enough.. but I'm not sure..
If you want to ask me to explain more.. please do so...

Please help.

Thanks.
 
Try something like this:
Code:
nawk -F&quot;;&quot; '
/^[13];psf\/210;/{printf &quot;%s;%s;%s;%s;%s&quot;,$1,$2,$3,$4,$5
  for(i=9;i<=2231;i+=202) 
    printf &quot;;%s;%s;%s;%s&quot;,$(i+4),$(i+6),$(i+18),$(i+20)
  printf &quot;\n&quot;
}
/AnotherCondition/{Another printf
}' $filen >>${pathOut}/psf_210_${dateFile}.txt

Hope This Help
PH.
 


Thanks PH,

But something wrong happen when i tried to run your lines,
this is the warning :
nawk: trying to access field 619
input record number 1, file Paysf11.txt
source line number 4

and to make things more clear.
I still want to do like this :

grep &quot;^[13];psf\/210;&quot; $filen | cut -d&quot;;&quot; -f$List >> ${pathOut}/psf_210_${dateFile}.txt


the $List is created before grepping, not while grepping...
from your lines, i can tell that the list created while grepping.
This is the old script mechanism :
- Create a $List consist of numbers,
- The numbers are taken from the iteration :
for(i=9; i<=2231; i+=202) {
printf(&quot;,%d,%d,%d,%d&quot;,i+4,i+6,i+18,i+20) } }
-> result:
13,15,27,29
215,217,229,231
...
(and so on)
- This $List will be taken by the grep line.
- grep &quot;^[13];psf\/210;&quot; $filen | cut -d&quot;;&quot; -f$List
from the file Input ($filen) we will take our columns
- the columns are represented by the numbers within the
$List

I'm realy sorry for being pushy.. but I'm really stuck and have no idea what to do with this awk things...
I only have ideas.. but not knowing how to put them in awk..

please help..........
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top