Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
Get part of multiple files (Read 2131 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Get part of multiple files
12.09.09 at 08:34:08
 
Get part of multiple files
 
If you have a set of files and want to get a portion of each file you can use the sed utility to do this. First use the find command to find the files and then execute sed to get portion of the file. Note that I also added a -print which prints the file name as I require it to separate the output for the various files:
 
find . -name pm.output -print -exec sed -n -r "900,1000p" '{}' \;
 
Explanation
find: the find file utility
. : start the search in the current directory
-name : to indicate I want to search files on the basis of their file names
pm.output : the name of the files I want to search (in different directories)
-print : prints the found file names
-exec : for each found file execute a command followed by the command to execute
'{}'\; : I don't know why this is necessary but I use it for each find .... -exec
sed : the text utility
-n -r : I don't know why this is needed
"900,1000d" : get lines 900 to 1000
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Get part of multiple files based on search strings
Reply #1 - 12.09.09 at 08:51:32
 
Get part of multiple files based on search strings
 
find . -name pm.output -print -exec sed -n "/ Mulliken charges/,/LoProp/p" '{}' \;
 
Finds all files called pm.output starting in the current directory and recurses in all sub dirs
For each found file the name is printed (-print) and the sed command is executed.
All lines are diplayed after finding string "Mulliken charged" until the string "LoProp" is found.
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1