- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to extract from a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 12:47 AM
тАО03-22-2002 12:47 AM
I have a long file in which there are some recursive strings. I need to find the last one and extract it with 6 lines before and 12 lines after. Please help me.. it's urgent
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 01:22 AM
тАО03-22-2002 01:22 AM
Re: how to extract from a file
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 01:26 AM
тАО03-22-2002 01:26 AM
Re: how to extract from a file
can you put a little example of your file and desired output?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 01:35 AM
тАО03-22-2002 01:35 AM
Re: how to extract from a file
Example: STRING is the recursive string
tguyt
khhjh
STRING
reqrteqw
qewrtqrew
qwertqew
qwerrrrrrrrr
gyf
wert2w
q4ewt4te
tqtrew
jirt
reuii
gfsiu
iewutoiqu
tyql
STRING
ytuyltlyu
rwhrw
dthy
weryw
wqeyte
eqr
qeryt
ywyt
reytwqe
tqety42
tqer
qtet2
2tyty
yqeyq
qeyt2qet
qeyrwyewq
qyeyqy
qeyyyqeyt
STRING
yutuytlyu
]htgytyu
htuyt
uyiuyiu
iuiou'
uy;uiyu
juyh;ouiy
uyuy
1345
gaqaq
qre
qrew
rtw
t341
1434t31
I Should get :
2tyty
yqeyq
qeyt2qet
qeyrwyewq
qyeyqy
qeyyyqeyt
STRING
yutuytlyu
]htgytyu
htuyt
uyiuyiu
iuiou'
uy;uiyu
juyh;ouiy
uyuy
1345
gaqaq
qre
qrew
rtw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 01:40 AM
тАО03-22-2002 01:40 AM
Re: how to extract from a file
awk ' $1 == "STRING" { print NR-6","NR+12"p"}' file > sed_file
sed -n -f sedfile file
Goood luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 01:41 AM
тАО03-22-2002 01:41 AM
Re: how to extract from a file
Hi,
I do not quite understand what you mean
by recursive string.
But if you can use grep to find the line
number for the last occurence of the string,
I have a program that can read a sequence
of lines from a start-point to an endpoint
(linenumbers)
I used this to extract data from very large
logfiles from ccm.
Olav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 02:24 AM
тАО03-22-2002 02:24 AM
Re: how to extract from a file
Can you try and tell me what can i do ?
federico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 02:39 AM
тАО03-22-2002 02:39 AM
SolutionThe question is to get linenumbers and create a file that sed command can undestand.
I have copy/paste your example and it not works because the ocurrence of "STRING" is in line #3, so sed says :
sed: -3,15p is not a recognized function
but this is only because a negative linenumber.
Try this new
awk ' $1 == "STRING" { print NR-6","NR+12"p"}' 77 > sed_77
sed -n -f sed_77 77 >77_out
Then edit sed_77 file and change -3 by 1, and run sed command.
It works for your example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 02:53 AM
тАО03-22-2002 02:53 AM
Re: how to extract from a file
You could put a conditional operator in the awk statement, to force the start line to be greater than zero:
# awk ' $1 == "STRING" { printf (NR>7) ? NR-6 : 1 ;print","NR+12"p"}' file | tail -1 > sedfile
# sed -n -f sedfile file
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2002 03:13 AM
тАО03-22-2002 03:13 AM
Re: how to extract from a file
2tyty
yqeyq
qeyt2qet
qeyrwyewq
qyeyqy
qeyyyqeyt
STRING
yutuytlyu
]htgytyu
htuyt
uyiuyiu
iuiou'
uy;uiyu
juyh;ouiy
uyuy
1345
gaqaq
qre
qrew
l1:/tmp 114 >