LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2016, 07:34 AM   #16
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918

here are the results:
Code:
[schneidz@hyper ~]$ awk 'NF == 2' p12345.tab #1
hello	world
all3r	sp1ca
l33t	h4x0rz
boston	celtics
[schneidz@hyper ~]$ awk -F"\t" 'NF != 1 && $2 !~ /          |^$/' p12345.tab #2
hello	world
all3r	sp1ca
l33t	h4x0rz
boston	celtics
[schneidz@hyper ~]$ awk -F '\t' '{ picker = $2; gsub(" .*", ""); if(picker != "") print $1 FS $2 }' p12345.tab #3
hello	world
stanley	
all3r	sp1ca
l33t	h4x0rz
boston	celtics
[schneidz@hyper ~]$ awk -F '\t' '(index($2, "        ") == 0) && (index($2, "") == 0) {print $1 "\t" $2}' p12345.tab #4
[schneidz@hyper ~]$ awk -F '\t' '$2 != "        " && $2 != "" {print $1 "\t" $2}' p12345.tab #5
hello	world
stanley	          
all3r	sp1ca
l33t	h4x0rz
boston	celtics
in retrospeck, my filtered down example was not representative of the original data so #1 and #2 will not filter out some appropriate lines.

edit: this seems to work in the original data that ocntains 9 fields but not the test i created for some reason:
Code:
[schneidz@hyper ~]$ awk -F '\t' '(index($2, "        ") == 0) && (index($2, "") != 0) {print $1 "\t" $2}' p12345.tab
hello	world
all3r	sp1ca
l33t	h4x0rz
88888888	
boston	celtics

Last edited by schneidz; 04-08-2016 at 08:38 AM.
 
Old 04-08-2016, 05:19 PM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
my filtered down example was not representative of the original data so #1 and #2 will not filter out some appropriate lines.
Obviously difficult to tailor a solution if you do not show the type of data. I am curious if the red information shown are errors, ie not supposed to be shown, or are more
correctly showing what you were looking for?

It is also unclear if #4 is not working as that also seems to be the same as the final script shown which does produce output?
 
Old 04-08-2016, 07:23 PM   #18
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Original Poster
Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by grail View Post
Obviously difficult to tailor a solution if you do not show the type of data. I am curious if the red information shown are errors, ie not supposed to be shown, or are more
correctly showing what you were looking for?

It is also unclear if #4 is not working as that also seems to be the same as the final script shown which does produce output?
red are errors; in #4 this didnt work :
Code:
(index($2, "") == 0)
but i changed it to this:
Code:
(index($2, "") != 0)
its healthcare information so i am anxious to not just copy-pasta it.

Last edited by schneidz; 04-08-2016 at 07:25 PM.
 
Old 04-08-2016, 08:09 PM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
ahh ... the old not equal to switcheroo .. hehe

Yes I certainly don't mean to place the exact data if it is sensitive, just that making a script to do the job would need to see the same type of fields

You have a working solution though, so all good
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK script Replace Blank Fileds with Previous non blank fields mjunaid CentOS 1 02-10-2015 04:17 PM
Cutting fields from lines with multiple spaces 915086731 Linux - Software 6 09-07-2011 09:51 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
fscanf with optional fields, spaces? phyx Programming 1 01-26-2007 05:16 PM
filter a data sheet for blank spaces tjgadu Linux - Newbie 2 04-20-2006 11:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration