Help required in searching of pattern.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required in searching of pattern.
# 8  
Old 02-01-2014
I tried below but it is giving error.

Code:
sed "s/^abcd.com\(.*\)A\(.*\)\$/^abcd.com\1A\2/15\.1\.1\.10$" abcd.com

# 9  
Old 02-01-2014
So you want to change 15.1.1.1 to 15.1.1.10 and 151.100.151.100 to 151.100.151.200? Try (untested)
Code:
sed "/^abcd\.com/s/15\.1\.1\.1$/15.1.1.10/; /^server\.abcd\.com/s/151\.100\.151\.100$/151.100.151.200/" abcd.com

# 10  
Old 02-01-2014
Yes true, but i have one question, for first and second both record you are breaking source ip address in block while target ip address you are not breaking... why?

---------- Post updated at 04:37 PM ---------- Previous update was at 04:32 PM ----------

One more thing, how i can add increment in serial number.

current serial number

Code:
2006080401


target serial number

Code:
2006080402

I have tried this

Code:
x=2006080401

output=`expr $x + 1`

echo $output
2006080402


But problem is that i am hardcoding the serial number, is it possible i can grep the only serial number directly and only increment in last two digit.

Serial number format is this.

Code:
2006080401	; serial

# 11  
Old 02-01-2014
In sed's s(ubstitute) comamnd, the first term is a regex so you need to escape the dots (if you want to be very accurate), while the second is just plain text (except for e.g. \n).
If you want to do arithmetics, you'd be better off utilising tools like awk or perl, where you can modify the IPs as well as serial No.s in one single script.
# 12  
Old 02-01-2014
Quote:
Originally Posted by RudiC
In sed's s(ubstitute) comamnd, the first term is a regex so you need to escape the dots (if you want to be very accurate), while the second is just plain text (except for e.g. \n).
If you want to do arithmetics, you'd be better off utilising tools like awk or perl, where you can modify the IPs as well as serial No.s in one single script.
Please can you give me any example of awk or perl, how i can achieve that?
# 13  
Old 02-02-2014
I really didn't understand your requirement,

Quote:
Originally Posted by learnbash
i m searching a zone file my domain name is abcd.com


my zone file looks like this.

Code:
abcd.com.       IN      SOA     ns1.abcd.com.      root.abcd.com. (
               

abcd.com.               400     IN      A       15.1.1.1

Then i am searching that abcd.com have if below ip address or not, if not then echo ip address is different. But problem is that i am not able to search the domain name with ip address because domain name is also having SOA record. abcd.com.zone is file name of zone file.

Code:
grep ^abcd.com. abcd.com.zone  | fgrep 15.1.1.10 | awk {'print $5'}

Quote:
Originally Posted by learnbash
Thanks Don.....

I need one more help, how to change the ip address of domain name. It only change to below domain not disturb sub-domain or any other thing.

current output

Code:
abcd.com.               400     IN      A       15.1.1.1

server.abcd.com      400      IN      A       151.100.151.100

Desired output

Code:
abcd.com.               400     IN      A       15.1.1.10

server.abcd.com      400      IN      A       151.100.151.200

Please explain us clearly..

@ Don Cragun :
you might remember we have seen same kind of issue in last post also.. he didn't tell us clearly what is need to be done.



Changes of text in a file | Unix Linux Forums | Shell Programming and Scripting
This User Gave Thanks to Akshay Hegde For This Post:
# 14  
Old 02-02-2014
I agree to what others say: show us your efforts, and we'll be glad to help. First effort would be to compose a clear and unambiguous specification of what you need and where you come from. This effort would be rewarding by increasing chances for yourself to solve the problem on your own.
Try to search these fora for examples of using awk to perform some arithmetics. But be aware that your desire is not to just increase a "serial number" but that this serial number has some structure (YYMMDDNN) to it: What should happen if NN exceeds 99? What if you modify a file that was last modified yesterday? last month? year?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching and printing only required pattern

Hi all, i am trying to count the number of logical processors from the below output: # print_manifest | grep "logical processors" 8 cores, 16 logical processors per socket 2 logical processors (2 per socket) i just want to have below output : 16 2 also... (11 Replies)
Discussion started by: omkar.jadhav
11 Replies

2. Shell Programming and Scripting

Searching for a pattern and extracting records related to that pattern

Hi there, Looking forward to your advice for the below: I have a file which contains 2 paragraphs related to a particular pattern. I have to search for those paragraphs from a log file and then print a particular line from those paragraphs. Sample: I have one file with the fixed... (3 Replies)
Discussion started by: danish0909
3 Replies

3. UNIX for Dummies Questions & Answers

searching pattern in VI

in my file i have somthing likre kpk_12 kpk_1 kpk_1.tcl kpk_3.tcl kpk kpk kpk i want search only kpk i am using this cmd /kpk ...results it is showing all . any cmd is ther other then this to search exactword in this example kpk it shoulsnot show kpk_* etc Thanks in Advance ... (2 Replies)
Discussion started by: prakumar
2 Replies

4. UNIX for Dummies Questions & Answers

Pattern searching

Hi, I need small help from you people. In a directory there are around 150 odd files and few them contain the word "TRACK" and few are not. How can I find out the the list of those files which doesn't contain the word "TRACK"? Thanks, Siba (4 Replies)
Discussion started by: siba.s.nayak
4 Replies

5. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

6. Shell Programming and Scripting

Searching using awk - Help required

Hi... I am working on script to search some records in a file based on certain fields and each record is a ASCII fixed size. I was using awk to search based on certain condition. But the length of the record is too much that awk is giving syntax error near unexpected token `(' Request... (5 Replies)
Discussion started by: ysrikanth
5 Replies

7. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

8. Shell Programming and Scripting

searching for a pattern

can anybode tell me ? I want to search for a pattern present in a whole directory and subdirectories's files containg " crat" I tried grep -r "crat" */* ; is it right ? (3 Replies)
Discussion started by: pranabrana
3 Replies

9. Shell Programming and Scripting

Pattern searching pattern in c files

I have a problem in searching a specific pattern in c files. My requirement: I have to find all the division operator in all cfiles. The problem is, the multi line comments and single line comments will also have forward slash in it. Even after avoiding these comments also, if both... (6 Replies)
Discussion started by: murthybptl
6 Replies

10. Shell Programming and Scripting

Regarding Searching Pattern

Hi Guys, Can you help with the shell script: I would like to search a fixed width pattern from a file say for each line from a fixed position and lenght it has to return all rows from the file. Example: To search the third column for "def" it has to return 1 and 4th rows only ... (2 Replies)
Discussion started by: sbasetty
2 Replies
Login or Register to Ask a Question