- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: File handling to fetch records
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
тАО06-02-2008 08:56 PM
тАО06-02-2008 08:56 PM
I need to fetch records from the file by checking some condition. Please find the sample of records in the file.
I/P file
0350000000013502400107395824*Pamela Anne Lentine*Calvary Electric*****Lentine, Pamela Anne**45 ----first records end
0429000000013702600468749296*GESCO ASESORIA DE EMPRESAS, SL********PASEO DE ALMERIA - PLT 2 63**ALMERIA**1404**ALMERIA**04001
*SPAIN*693*3***---second records end
0725000000013802800899116768*AVG SiderM-#rgia Ltda.*AVG SiderM-#rgia*Siderurgica Ita Min Ltda*AVG Siderurgia Ltda*A V G Sider
urgia Ltda****Rua GrM-Fo ---third records end
Now I want to fetch only records from the file whose first five fields must be greater then 0500.
So my o/p file should contains following records
O/P
0725000000013802800899116768*AVG SiderM-#rgia Ltda.*AVG SiderM-#rgia*Siderurgica Ita Min Ltda*AVG Siderurgia Ltda*A V G Sider
urgia Ltda****Rua GrM-Fo
Logically i need to cut first five fields then compare whether it's greater then 0500 if yes fetch the whole records or read next records. but i unable to put above logic syntactically.
Could you please provide me the commands and if possible syntax as well .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2008 10:01 PM
тАО06-02-2008 10:01 PM
Re: File handling to fetch records
>i need to cut first five fields
Did you mean the first 4 columns/bytes?
awk '
{
value1 = substr($0, 1, 4)
if (value <= 500)
next
print $0
} file
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-02-2008 10:37 PM
тАО06-02-2008 10:37 PM
Re: File handling to fetch records
value1 = substr($0, 1, 4)
if (value1 <= 500)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2008 02:11 AM
тАО06-03-2008 02:11 AM
Re: File handling to fetch records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2008 02:47 AM
тАО06-03-2008 02:47 AM
Re: File handling to fetch records
Is this record one continuous line with a NewLine at the end?
0350000000013502400107395824*Pamela Anne Lentine*Calvary Electric*****Lentine, Pamela Anne**45 ----first records end
Or are there mulitiple Newlines?
As well do you need to just compare the first four characters 0350 against 0500?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2008 03:57 AM
тАО06-03-2008 03:57 AM
SolutionYou write 'five fields' twice, but the text suggest '4 characters'. Was there a leading space which dissapeard in teh web page formatting?
>> if yes fetch the whole records or read next records
You write "if ... do this or do that"
Did you mean "if ... do this else to that" ?
A solution might be:
$ awk '0+substr($0,1,4) > 500' input-file
- The "0 + " forces the value to become numeric for comparison.
- The empty action defaults to 'print current line'.
- awk always loops through all records.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2008 03:58 AM
тАО06-03-2008 03:58 AM
Re: File handling to fetch records
Judging from what you posted for sample data, it would appear that your record delimiter is simply a newline. Thus:
# perl -ne 'print if substr($_,0,4) >= 500' file
...would print records whose first (zero-relative) column for four characters is greater or equal to 500.
*PLEASE* also read:
http://forums12.itrc.hp.com/service/forums/helptips.do?#28
You have answers to previous questions that you have not yet evaluated. These questions of yours can be found by looking at your profile:
http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1236026
http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1236353
Providing feedback to the responses to your questions helps the community at large determine which answers solved your problem.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2008 04:16 AM
тАО06-03-2008 04:16 AM
Re: File handling to fetch records
Kevin - The new records start with new line. There is no multiple new line.I need to compare only first five byte as mentioned by you but need to fetch record if condition is true.
Hein van den Heuvel - i need to check first five field (0350) if it's greater then 500 then fetch the complete records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2008 07:00 AM
тАО06-03-2008 07:00 AM
Re: File handling to fetch records
you seem to consider Heins solutions as incomplete - why?
Perhaps:
1) You stated 'greater than 0500' - this leads to '>'. But because you want to get a line starting 0500, you mean '>=' .
2) The first *five* bytes for the first line seem '03500' to me - not '0350' as you told us:
Either that are only four bytes or your string is incomplete. 1) + 2) may lead to
awk '0+substr($0,1,5) >= 5000'
3) The first '0' - is it used to get an octal representation of a number or is it just used to fill the record?
mfG Peter
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-03-2008 10:08 AM
тАО06-03-2008 10:08 AM
Re: File handling to fetch records
You don't need to add but you do need to say where they begin and end.
>please find the sample of records in first post.
As I mentioned, this wasn't good enough.
You need to attach a file and give definition of your record "key".
>MK: 3) The first '0' - is it used to get an octal representation of a number or is it just used to fill the record?
Only broken C does that octal junk.