- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- File interrogation
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
тАО02-25-2003 04:49 PM
тАО02-25-2003 04:49 PM
I have a file named
ABCxxxx.txt where xxxx changes but ABC remains constant.
Within file ABCxxxx.txt I should have the following fixed layout:
aa,xxxx,bb,cccc where the second column should always match the xxxx digits in the file name.
What's the most efficient way to:
a) test the 'xxxx' in the filename against the 'xxxx' in every row of the file? (I know how to get the xxxx out of the filename; it's the testing against the records I'm unsure of);
b) How can I toss out those records that don't have a match?
Looking forward to your input!
Cath
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2003 04:50 PM
тАО02-25-2003 04:50 PM
Re: File interrogation
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2003 05:04 PM
тАО02-25-2003 05:04 PM
Re: File interrogation
#!/usr/bin/ksh
FILE=ABCXXXX.txt
MYNAME=$(echo $FILE|awk -F "." '{print $1}'|sed 's/ABC//g')
awk -v STR="$MYNAME" -F "," '$2 == STR {print $0}' $FILE > $FILE.new
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2003 05:06 PM
тАО02-25-2003 05:06 PM
Re: File interrogation
The above will create a new file called ABCXXXX.txt.new. You will still have the original file preserved. Replace ABCXXXX.txt with your file
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2003 08:22 PM
тАО02-25-2003 08:22 PM
Re: File interrogation
awk -v STR=0139 -F , $2 == STR {print $0} ABC1390.txt
"awk: syntax error near line 1"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2003 08:48 PM
тАО02-25-2003 08:48 PM
Re: File interrogation
You changed the syntax of the awk statement. Copy and Paste the above script into a file - call it script. Replace ABCXXXX.txt with ABC1390.txt and run the script. It will produce ABC1390.txt.new.
Or run the command
awk -F "," '$2 == "0139" {print $0}' ABC1390.txt
will work for you if you have only one such file.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2003 09:20 PM
тАО02-25-2003 09:20 PM
Re: File interrogation
I figured out that my error was putting quotes around the comma separator. When I do -F, it works.
So the errors go to $FILE.new.
Where would the good data land? I need to end up with a file of good data and a file of bad data (if indeed there is bad data!) And you KNOW there's bad data in this world!
Cathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2003 12:08 AM
тАО02-26-2003 12:08 AM
Re: File interrogation
Any other ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2003 02:00 AM
тАО02-26-2003 02:00 AM
Re: File interrogation
could you please attach some authentic input containing good and bad records?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2003 08:00 AM
тАО02-26-2003 08:00 AM
Re: File interrogation
File ABC0041.txt:
05,0041,20030226,15
Bad file:
File ABC1346.txt
10,0139,20030226,15
I need to test the second column in the file make sure it matches the four digits in the file name. If the data's good it should go to one file; if it's bad it should go to another.
Thanks!
Cathy