Gurus,
I have a big file that needs to be sorted out and I cant figure out what to do. The file name is as below:
Name: xxxx yyyy nnnn
Description: dfffgs sdgsgsf hsfhhs
afgghhjdgj
fjklllll gsfhfh
Updated: jafgadsgg gsg
Corrected: date today
The file consists of line like these.
I want to only print out the line with the "Name" and "Updated" including all the lines between them.
Appreciate your help.
awk '$1=="Update:"{f=0}$1=="Name:"{f=1}f' file
awk "/Name/,/Updated/" file
or:
sed -n '/Name/,/Updated/p' file
1 Like
It works wonders! Thanks so much
sed -nf scr input.txt
scr contains:
/Name:/,/Updated:/{
w abc.txt
}
input.txt contains:
Name: xxxx yyyy nnnn
Description: dfffgs sdgsgsf hsfhhs
afgghhjdgj
fjklllll gsfhfh
Updated: jafgadsgg gsg
Corrected: date today
output ie abc.txt contains:
Name: xxxx yyyy nnnn
Description: dfffgs sdgsgsf hsfhhs
afgghhjdgj
fjklllll gsfhfh
Updated: jafgadsgg gsg
Here w writes into a file.
kurumi
6
$ ruby -ne 'print if /Name/../Updated/' file
what if i dont want the "Updated" included? like it will only print lines from "Name" until before "Updared"?
awk '/Update/{f=0}/Name/{f=1}f' file
when i ran danmero code, i got from line Name to before updated :
awk '$1=="Updated:"{f=0}$1=="Name:"{f=1}f' file
is that what you wanted?
i just want to get an output of:
Name: xxxx yyyy nnnn
Description: dfffgs sdgsgsf hsfhhs
afgghhjdgj
fjklllll gsfhfh
without the "Updated" line.
---------- Post updated at 09:44 AM ---------- Previous update was at 09:35 AM ----------
i've got syntax error "bailing out near line 1"
---------- Post updated at 09:44 AM ---------- Previous update was at 09:44 AM ----------
i've got syntax error "bailing out near line 1"
hi,
as per this you might be using old one for awk.
please try using nawk instead of awk.
sed -n '
/Name/,/Updated/{
/Updated/!p
}
' file