Linux - NewbieThis forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I 'd like to find out a command to search among all *.dat files in a certain path (including subdirectories) looking for the following text in them:
Code:
--------------------------------------------------------------------------------
Elements with small area
Element Adjusted nodes
--------- --------------
16294 NO
17889 NO
and getting the list of elements with small area printed in a file "ErrorEl.txt". The output should have this form:
"/path/01/A.dat
bad-el#01
bad-el#02
/path/04/A.dat
bad-el#01
bad-el#02
bad-el#03
"
How to do it?
I know already how to find out the dat files containg a certain string
Code:
c=/path/
grep -R --include="*.dat" "Elements with small area" $c | cut -d: -f1>> ErrorEl.txt
but I don't know then how to get the element numbers(16294 and 17889 in the example above)
PS: also a bash script would be ok.
Many thanks for help. Alex
You can use "grep -lR PATTERN FILES" to list the file names which will become INPUT_FILE of the above command. You can write a short script or use Pipes to get the input files.
Contents (Lines) of your "bad.dat" becomes search pattern now. Read the contents of your bad.dat files linewise and each line is now your search pattern. You can replace those lines with a 'd' (eg: g/PATTERN/d in Vi, or /PATTERN/d in SED), this will delete those line.
is actually what I need, but instead of 10,100 my range-delimiters are to be found (referring to the text I posted) with the first orange-line "*Element, type=DC2D3" and the first non-orange-line "*Elset, elset=C".
in the posted text (including the orange selection) "..." represents a large amount of lines in the same format of the previous ones, just with different numbers.
I cannot post the entire file content because it is too huge.
is actually what I need, but instead of 10,100 my range-delimiters are to be found (referring to the text I posted) with the first orange-line "*Element, type=DC2D3" and the first non-orange-line "*Elset, elset=C".
thanks,
Alex
I take that your delimiters are "Element, type=DC2D3" and "Elset, elset=C". My commands are colour blind
Try:
Code:
echo "/Element, type=DC2D3"; echo "ma a"; echo "/Elset, elset=C"; echo "ma b"; echo "'a,'bg/$P/d"
Explanation:
1. first search for first occurrence of "Element..." pattern.
2. mark this line as 'a'
3. search for first occurrence of "Elset..."
4. mark this line as 'b'
5. within 'a to 'b do a g/$P/d
May be someone else can suggest a better or easier method. I think awk should handle this more cleanly, but I dont know awk.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.