search a replace each line- help needed ASAP


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users search a replace each line- help needed ASAP
# 15  
Old 05-29-2008
Hi Era,


If "9” is in column 21 and ‘00000000’ in column 123 then i need to Change the ‘00000000’ starting in column 123 to ‘19000101’.
This needs to works irrespective of if there are any spaces or not in the file.

The tried your code and it does not give me the required output.

The file is as below:

0011200ALN00000000009EGYPT 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062 004O000000000000000000000000000000000000000000000000390440000000000000450140460440000000000000190010 000000000000000000

This is just an example record and spaces vary in the file. But the "9” in column 21 and ‘00000000’ in column 123 remain in the saem positions irrespective of wherever the space is.

Can you please relook into this one.

Will be very helpfull.
# 16  
Old 05-29-2008
If the offsets are different then change them. Based on what you posted before, the script looks for "9" in column 21 and "1999" in columns 42-45 (starting at 42, 4 positions). It's easy enough to change those.

Again, please use code tags when posting examples with significant spaces.
# 17  
Old 05-29-2008
Hi era,

Thanks so much for the quick reply

I made the required chnages as below in ur code:

awk 'substr($0,21,1)==9 && substr($0,123,8)==00000000{print substr($0,0,122) "19000101" substr($0, 131); next }1'

But this does not give me a result.


Can you please guide me on how i can use code tags when posting examples. Sorry but i am using this for the first time.
# 18  
Old 05-29-2008
I linked to this up in my earlier reply: The UNIX Forums - vB Code List

You might need to put the 000000 in double quotes. (My mawk doesn't require that, but it seems like a possible problem.)
# 19  
Old 05-29-2008
Hi era,

I have attached the file to this post.

the file name is 123F.txt

Thanks,
Sandeep

Last edited by bsandeep_80; 05-29-2008 at 03:02 PM..
# 20  
Old 05-29-2008
It doesn't give a result because your file has no record that fits the condition.
# 21  
Old 05-29-2008
Hi Era,

Your are correct "" was the issue that was not allowing the file to be chnaged. I made the chnage and it worked.

Thanks a tonSmilie

Regards,
Sandeep
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

2. Shell Programming and Scripting

Search for a pattern and replace. Help needed

I have three variables $a, $b and $c $a = file_abc_123.txt $b = 123 $c = 100 I want to search if $b is present in $a. If it is present, then i want to replace that portion by $c. Here $b = 123 is present in "file_abc_123.txt", so i need the output as "file_abc_100.txt' How can this be... (3 Replies)
Discussion started by: irudayaraj
3 Replies

3. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

4. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

5. UNIX for Advanced & Expert Users

Search Parameter in first line and replace next line content

Hi, I need help. I have XML file as below &lt;a n=&quot;infoLevel&quot;&gt; &lt;v s=&quot;true&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;localAddr&quot;&gt; &lt;v s=&quot;server.host.com&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;ListenPort&quot;&gt; &lt;v s=&quot;21111&quot;/&gt; &lt;/a&gt; I need to find variable "ListenPort" in line and then replace... (4 Replies)
Discussion started by: rdtrivedi
4 Replies

6. Shell Programming and Scripting

Complex Search/Replace Multiple Files Script Needed

I have a rather complicated search and replace I need to do among several dozen files and over a hundred occurrences. My site is written in PHP and throughout the old code, you will find things like die("Operation Aborted due to....."); For my new design skins for the site, I need to get... (2 Replies)
Discussion started by: UCCCC
2 Replies

7. Shell Programming and Scripting

KERBEROS_V4 -help needed ASAP

#!/bin/sh HOST='ftp.bend.com' USER='temp1' PASSWD='temp2' FTPPATH='SY1:' ifile='concat.txt' #FTP concatenated file ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD binary cd $FTPPATH put $ifile get $ifile retrieval.$$ quit END_SCRIPT if then echo "FTP of... (2 Replies)
Discussion started by: Sgiri1
2 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question