Originally Posted by
ghostdog74
Code:
awk '/build/{
# if build is found
f=0 #remove flag
print $0 # print the current line
for(i=1;i<=d;i++){ print a[i] } #print the array of lines after source and before build...
Not sure how the array understands to the source line, but thanks for the explanation. I'm getting to like how awk works.
Originally Posted by
benj1
how did you call it ?, it should be
Code:
thisscriptfile.awk foofile.txt
...
Yeah, I called this from my script path which is a hidden folder. I'm thinking your script is interpretting the . as a regexp variable???
Originally Posted by
geirha
I believe this ed should do it. Note that it edits the file in-place.
Code:
printf "%s\n" "/^build/d" "/^source/x" "w" | ed -s file.txt
It sends three commands to ed...[/code]
Yeah, I originally wrote the thread trying to remember this command. I had seen 'ed' before but didn't remember it. +1 for helping me remember this and for ease of use.
I've run into a bit of a problem though. At times, (I've discovered) the source and build lines expand over more lines. For example:
Code:
source=('78905905f5a4ed82160c327f3fd34cba'
'5277a9164001a4276837b59dade26af2'
'3f8b60b6fbb993c18442b62ea661aa6b')
build=('a-file-name'
'another-file-name')
I've tried using the ed command and defining a range:
Code:
printf "%s\n" "/^build/,/)/d" "/^source/,/)/x" "w" | ed -s file.txt
with no luck. Can I do this with 'ed'??? Or anyone know a way to get awk to do it??
Bookmarks