Diff with Regular Expressions


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Diff with Regular Expressions
# 1  
Old 05-02-2008
Diff with Regular Expressions

Hi everybody

I'm trying to use diff to find the differences between two files and show the section of the file where the difference occurred. Diff allows you to use a regular expression to mark the last section header before the difference with the -F flag. That's all fine.

My problem is is that only the first 40 characters of the section lines are shown. Most of my section headers are longer than that (100 characters+) and I would like to be able to see it all, especially since some sections begin the same.

Input:
diff -F [[] -u file1 file2
Output:
@@ -1, 1 +1, 1 @@ [FILE1-CHAPTER-1-SECTION-1-HEADER-MORE-T

The full line should read [FILE1-CHAPTER-1-SECTION-1-HEADER-MORE- THAN-FORTY-CHARACTERS. The line is just an example, the actual headers are more meaningful and cant be reduced to less than 40 chars.

The diff manual says I can use more than one regex for such lines. Can anybody give me an example... Or suggestions... Thanks
# 2  
Old 05-03-2008
It looks like you have GNU diff. In info you will see
Quote:
--LTYPE-line-format=LFMT
Similar, but format LTYPE input lines with LFMT.

LTYPE is `old', `new', or `unchanged'.
GTYPE is LTYPE or `changed'.

GFMT may contain:

%< lines from FILE1

%> lines from FILE2

%= lines common to FILE1 and FILE2

%[-][WIDTH][.[PREC]]{doxX}LETTER
printf-style spec for LETTER
You can specify the number of characters in a changed line this way, it is very much like a printf format string - the "for LETTER" bit refers to the line type

Last edited by jim mcnamara; 05-03-2008 at 07:54 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions

I need to pick a part of string lets stay started with specific character and end with specific character to replace using sed command the line is like this:my audio book 71-skhdfon1dufgjhgf8.wav' I want to move the characters beginning with - end before. I have different files with random... (2 Replies)
Discussion started by: XP_2600
2 Replies

2. Shell Programming and Scripting

Regular Expressions

Hi Ilove unix and alwyas trying to to learn unix,but i am weak in using regular expressions.can you please give me a littel brief discription that how can i understand them and how to use .your response could lead a great hand in my unix love. (1 Reply)
Discussion started by: manoj attri
1 Replies

3. Shell Programming and Scripting

Help with regular expressions

I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like: abc x93825 def 13234 x52673 hello output looks like: abc def 13234 hello Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
Discussion started by: pxalpine
7 Replies

4. Shell Programming and Scripting

Regular expressions help

need a regex that matches when a number has a zero (0) at the end of it so like 10 20 120 30 330 1000 and so on (6 Replies)
Discussion started by: linuxkid
6 Replies

5. Shell Programming and Scripting

Regular Expressions

what elements does " /^/ " match? I did the test which indicates that it matches single lowercase character like 'a','b' etc. and '1','2' etc. But I really confused with that. Because, "/^abc/" matches strings like "abcedf" or "abcddddee". So, what does caret ^ really mean? Any response... (2 Replies)
Discussion started by: DavidHe
2 Replies

6. Shell Programming and Scripting

Need help with Regular Expressions

Hi, In ksh, I am trying to compare folder names having -141- in it's name. e.g.: 4567-141-8098 should match this expression '*-141-*' but, -141-2354 should fail when compared with '*-141-*' simlarly, abc should fail when compared with '*-141-*' I tried multiple things but nevertheless,... (5 Replies)
Discussion started by: jidsh
5 Replies

7. UNIX for Dummies Questions & Answers

regular expressions

how to find for a file whose name has all characters in uppercase after 'project'? I tried this: find . -name 'project**.pdf' ./projectABC.pdf ./projectABC123.pdf I want only ./projectABC.pdf What is the regular expression that correponds to "all characters are capital"? thanks (8 Replies)
Discussion started by: melanie_pfefer
8 Replies

8. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

9. Shell Programming and Scripting

Help with regular expressions

I have following content in the file CancelPolicyMultiLingual3=U|PC3|EN RestaurantInfoCode1=U|restID1|1 ..... I am trying to use following matching extression \|(+) to get this PC3|EN restID1|1 Obviously it does not work. Any ideas? (13 Replies)
Discussion started by: arushunter
13 Replies

10. Programming

regular expressions in c++

How do I use the regular expressions in c++? (2 Replies)
Discussion started by: szzz
2 Replies
Login or Register to Ask a Question