- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Cheap points for script gurus !! ;p
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
Forums
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
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
тАО09-10-2001 09:51 AM
тАО09-10-2001 09:51 AM
I have a file that I know will contain these values at a FIXED position:
T200
R200
I want to split this one file into two separate files. One file containing the T200's and one file containing the R200's.
Now, this would be a piece of cake had it not been for the fact that T200 could also appear on "R200-lines" and vice versa. The only thing that will help me is the fact that the T200's and R200's do infact come atleast once and in the exact same spot each time.
Examples:
FileA without problem:
sometextT200sometextheretoo
sometextR200sometextheretoo
sometextR200sometextheretoo
sometextT200sometextheretoo
sometextR200sometextheretoo
sometextR200sometextheretoo
FileB with problem:
sometextT200sometextheretoo
sometextR200sometextherT200
sometextR200sometextheretoo
sometextT200sometextherR200
sometextR200sometextheretoo
sometextR200sometextheretoo
see my problem ?
Please help !!??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:02 AM
тАО09-10-2001 10:02 AM
Re: Cheap points for script gurus !! ;p
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:12 AM - last edited on тАО07-03-2024 11:21 PM by Parvez_Admin
тАО09-10-2001 10:12 AM - last edited on тАО07-03-2024 11:21 PM by Parvez_Admin
Re: Cheap points for script gurus !! ;p
Hi Kent:
Attached is a shell script which calls awk. You will need to adjust the shell variable "OFFSET" to match the fixed location of your data.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:13 AM
тАО09-10-2001 10:13 AM
Re: Cheap points for script gurus !! ;p
OriginalFileA without problem:
sometextT200sometextheretoo
sometextR200sometextheretoo
sometextR200sometextheretoo
sometextT200sometextheretoo
sometextR200sometextheretoo
sometextR200sometextheretoo
I want to be split into two files like this:
File1
sometextT200sometextheretoo
sometextT200sometextheretoo
File2
sometextR200sometextheretoo
sometextR200sometextheretoo
sometextR200sometextheretoo
sometextR200sometextheretoo
(and same with)
OriginalFileB with problem:
sometextT200sometextheretoo
sometextR200sometextherT200
sometextR200sometextheretoo
sometextT200sometextherR200
sometextR200sometextheretoo
sometextR200sometextheretoo
I want split into:
File1:
sometextT200sometextheretoo
sometextT200sometextherR200
File2:
sometextR200sometextherT200
sometextR200sometextheretoo
sometextR200sometextheretoo
sometextR200sometextheretoo
Hope this was not too fuzzy .. ?:-\
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:13 AM
тАО09-10-2001 10:13 AM
Re: Cheap points for script gurus !! ;p
Oops wrong one, this should do it.
Attached is a shell script which calls awk. You will need to adjust the shell variable "OFFSET" to match the fixed location of your data.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:14 AM
тАО09-10-2001 10:14 AM
Re: Cheap points for script gurus !! ;p
I am not a guru but will try to help. This is really dependent on what your fixed position is. If you can show us the exact files, it may be easy to figure out.
If we just take the example you gave, i would do this way.
For ex., if you have the text like this
sometextT200sometextR200
sometextT200sometextT200
sometextR200sometextT200
If I want to get all T200 lines I would do
grep "^sometextT200" file > t200.stuff
If there is anything that is before the fixed position, then you can use that string in your grep command.
If it is a fixed field, you can use awk to match that field and print the line.
It's just dependent on what you have in the file.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:20 AM
тАО09-10-2001 10:20 AM
Re: Cheap points for script gurus !! ;p
grep "^........R200.*" testfile
where you pad out the dots till the first occurance of R200 (the dot, '.', represents any character). You could do the same for T200. Not the most elegant solution, but it works.
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:30 AM
тАО09-10-2001 10:30 AM
Re: Cheap points for script gurus !! ;p
while read LINE
do
KEY=$(echo $LINE |cut -c 0-12)
case $KEY in
T200)
echo $LINE >> file1
;;
R200)
echo $LINE >> file2
*)
;;
esac
done < infile
If you know that every line MUST have either R200 or T200 in the key position, drop the case and just use an if..then..else
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:37 AM
тАО09-10-2001 10:37 AM
Re: Cheap points for script gurus !! ;p
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 11:25 AM
тАО09-10-2001 11:25 AM
Re: Cheap points for script gurus !! ;p
I was about to send in the reply when i saw Alan's reply which was almost what i was submitting anyway.
I only had a small modification to that , since you already know the exact location, you want to use
cut -c 9-12 for the example you gave.
where 9 is the beginning and 12 is the end. (man cut for more information)
-Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 11:42 AM
тАО09-10-2001 11:42 AM
Re: Cheap points for script gurus !! ;p
I agree with both Patrick and Sridhar's solutions, they r simple and good. I don't think u need to go for spl scripts for that.
Cheers...
Satish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 12:42 PM
тАО09-10-2001 12:42 PM
Re: Cheap points for script gurus !! ;p
Santosh's answer is almost perfect, the only
improvement I can see is the omit ".*" at the
end of his pattern - it is not needed there.
Just my ?0.02,
Wodisch (I am european, but that should be about $0.02)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 10:38 PM
тАО09-10-2001 10:38 PM
Re: Cheap points for script gurus !! ;p
i would use no awk or perl, just a little bit grep:
grep "^........T200" >> t200.txt
grep "^........R200" >> r200.txt
Put in as many dots as you need as a placeholder for your fixed length Text befor your T200/R200 string. This grep says: grep every line starting with 8 characters of any type and the string T200. And don't care whats behind.
This is not a impressing solution, but it is working and really fast.
Hope this helps
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2001 11:04 PM
тАО09-10-2001 11:04 PM
Re: Cheap points for script gurus !! ;p
here my solution:
#!/bin/sh
:>File1
:>File2
awk '{
t=index($0, "T200")
r=index($0, "R200")
if(t>0)
{
if((r>0 && t
else
print $0 >>"File2";
}
else if(r>0)
{
if((t>0 && r
else
print $0 >>"File1";
}
}' File
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2001 05:54 AM
тАО09-12-2001 05:54 AM
Re: Cheap points for script gurus !! ;p
I hope I've given everyone points now.
ohh..btw:
grep "^........T200"
did the trick...
..there's som much to learn..
;)