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!

Search and replace in a array ??

Status
Not open for further replies.

bholav

Technical User
Jun 13, 2002
15
US
I have a patten like the one below, I need to search each field and replace the caracter if it meets a criteria

for example on line 1 below ,I'll search for a 1 , I'll check if its euqal to 1 ,if yes,don't do anything if not, replace the character with a "X" .
I also will leave the leading and trainling "." alone but replace the intermediate "."s with an "X"

Any help is much appreciated


. . . . . . . . . . . . 2 7 9 9 2 3 . . . . . . . . . . . .
. . . . . . . . . 2 . 9 9 . 9 1 . 1 1 . 1 . . . . . . . . .
. . . . . . . . 1 1 . 9 2 . 1 1 . 1 1 . 1 1 . 3 . . . . . .
. . . . . . 8 2 1 9 9 1 1 1 1 1 9 9 9 1 1 9 1 1 1 . . . . .
. . . . . 7 9 9 9 1 1 1 1 9 9 1 1 1 1 1 1 1 9 1 1 1 . . . .
 
It looks like I'm not the only one who is not sure what you want. Post a sample of the output you expect. CaKiwi
 
It looks like I'm not the only one who is not sure what you want. Post a sample of the output you expect. CaKiwi
 
Thanks for your replies CaKiwi,sorry I was out for the last few days. I was able to resolve the situation mentioned above.
I need your help on the usage of SKIP command. I need to skip say, first five lines,how do I do it?
Secondly, how do I rename a file based on the content of certain field ?
Thank you.
 
The awk program
Code:
NR>5
will print all lines starting at the sixth.
For your second question, you will need to be more specific about how you want to rename the file. CaKiwi
 
CaKiwi, here's my explanation on my second question. I have a file XXXXXXX that needs to be renamed by extracting line2 & line3 of the file .



line1:CEIVDE:TC2000FIN line2:TOL:D62857
line3:FAEWR:10F5
 
Depending on exactly how you want to create the name out of the first 2 lines, something like this might work.
Code:
mv f1 `awk '{fn=$0;getline;print fn $0;exit}' f1`
CaKiwi
 
CaKiwi,
which key do I use after awk just before open and close of flower bracket ? I'm sorry , new to AWK and trying my best...
 
It is a single quote. On my keyboard it is below the double quote on the rightmost key on the middle row of letters. The character before awk is a backtick, the top lefthand key on my keyboard. But you just cut and paste from this page to your window. CaKiwi
 
Was able to accomplish it, thanks a bunch !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top