Search Key in same file but at different positions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search Key in same file but at different positions
# 15  
Old 07-27-2010
Hi,

awk: Cannot find or open file $C

if i give the way you told i am getting the error as
Code:
awk: Cannot find or open file $WOR_/Work_TIR453220100721533.txt

My modified code
Code:
awk '{ 
   if ( substr($0, 392, 1)=="C" )
      DOC = substr($0, 28, 15)  substr($0, 386, 3)
   else
      DOC = substr($0, 28, 18)
   print $0 > "$WOR/Work_" DOC ".txt"
}' $INPUT/$param_InputFileName

# 16  
Old 07-27-2010
Sorry, I forgot a modification (Assume that WOR is'nt a shell variable):
Code:
awk '{ 
   if ( substr($0, 392, 1)=="C" )
      DOC = substr($0, 28, 15)  substr($0, 386, 3);
   else
      DOC = substr($0, 28, 18);
   print $0 > "WOR/WORK_" DOC ".txt"
}' $INPUT/$param_InputFileName

If WOR is a shell variable :
Code:
awk '{ 
   if ( substr($0, 392, 1)=="C" )
      DOC = substr($0, 28, 15)  substr($0, 386, 3);
   else
      DOC = substr($0, 28, 18);
   print $0 > Dir "/WORK_" DOC ".txt"
}' Dir=$WOR $INPUT/$param_InputFileName

Jean-Pierre.
This User Gave Thanks to aigles For This Post:
# 17  
Old 07-28-2010
Hi I tried with this option i got the below error
Code:
awk '{ 
   if ( substr($0, 392, 1)=="C" )
      DOC = substr($0, 28, 15)  substr($0, 386, 3)
   else
      DOC = substr($0, 28, 18)

   print $0 > $WOR "/WORK_" DOC ".txt"
}' $INPUT/$param_InputFileName

Error for above code:
Code:
awk: Field  is not correct.
 The input line number is 1. The file is inputfilename.
 The source line number is 6.




Them i read i have to put the awk in single quotes i tried to put this below way

Code:
awk '{ 
   if ( substr($0, 392, 1)=="C" )
      DOC = substr($0, 28, 15)  substr($0, 386, 3)
   else
      DOC = substr($0, 28, 18)

   print $0 > '"$WOR"' "/WORK_" DOC ".txt"
}' $INPUT/$param_InputFileName

ERROR For above code:

Code:
awk: Cannot divide by zero.

 The input line number is 1. The file is input filename.
 The source line number is 7.

# 18  
Old 07-28-2010
Why don't you try the code of my last post ?

Jean-Pierre.
This User Gave Thanks to aigles For This Post:
# 19  
Old 07-28-2010
Quote:
Originally Posted by aigles
Why don't you try the code of my last post ?

Jean-Pierre.
Thanks for all help.
It worked fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for specific key in a file and print it

Hi All, I have a file abc.txt Database unique name: NEPAL Database name: NEPAL Services: NEPAL_COB,NEPAL_PROD output i need is it should search "Services" and it that search "COB" word so output i need is like NEPAL_COB (3 Replies)
Discussion started by: amar1208
3 Replies

2. Shell Programming and Scripting

Search and replace specific positions of specific lines

Hi, I have a file with hundreds of lines. I want to search for particular lines starting with 4000, search and replace the 137-139 position characters; which will be '000', with '036'. Can all of this be done without opening a temp file and then moving that temp file to the original file name. ... (7 Replies)
Discussion started by: dsid
7 Replies

3. Shell Programming and Scripting

Search the key from a file to another file

Hi, I need help in solving the below need in UNIX. I have a file datafile as below pg1,dvn1,scls1,cls1,itp1,sku1 pg2,dvn2,scls2,cls2,itp2,sku2 and keyfile as below scls1,1000,a,b,c,d,p1 scls2,1001,a,b,c,d,p1 scls1,1000,a1,b,c,d,p1 scls2,2000,a,b,c,d,p1 (4 Replies)
Discussion started by: bhaski2012
4 Replies

4. Shell Programming and Scripting

Searching the content of one file using the search key of another file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search key is... (3 Replies)
Discussion started by: csim_mohan
3 Replies

5. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

6. Shell Programming and Scripting

awk script replace positions if certain positions equal prescribed value

I am attempting to replace positions 44-46 with YYY if positions 48-50 = XXX. awk -F "" '{if (substr($0,48,3)=="XXX") $44="YYY"}1' OFS="" $filename > $tempfile But this is not working, 44-46 is still spaces in my tempfile instead of YYY. Any suggestions would be greatly appreciated. (9 Replies)
Discussion started by: halplessProblem
9 Replies

7. Shell Programming and Scripting

Help adding a key word search to my script

Hello: I need help adding a key word search to my bash script. I have the following script. My boss whats the user to be able to add a search word e.g. unknown failures for the script to search the logs through and find the instances. I had originally done it so it grepped for unknown... (8 Replies)
Discussion started by: taekwondo
8 Replies

8. Shell Programming and Scripting

search for key word and execute

Hi, I am writing a shell (after 6-7 months)that has to receive text from another shell, check if the first line in the text has a key word and then execute different shell.I could come up with the below program structure, please suggest me if there is a better way to do it or please help me with... (14 Replies)
Discussion started by: rider29
14 Replies
Login or Register to Ask a Question