Shell script to read lines in a text file and filter user data

Thread Solved

Join Date: Aug 2008
Posts: 2
Reputation: e04047 is an unknown quantity at this point 
Solved Threads: 0
e04047 e04047 is offline Offline
Newbie Poster

Shell script to read lines in a text file and filter user data

 
0
  #1
Oct 21st, 2009
hi all,

I have this file [myfile.txt] with some user data.

example:
$cat myfile.txt
FName|LName|Gender|Company|Branch|Bday|Salary|Age
aaaa|bbbb|male|cccc|dddd|19900814|15000|20|
eeee|asdg|male|gggg|ksgu|19911216|||
aara|bdbm|male|kkkk|acke|19931018||23|
asad|kfjg|male|kkkc|gkgg|19921213|14000|24|
aera|bprb|male|cccc|pppp||15000|20|
.
.
. // and so on


So what I want to do is to take out (to a file) the missing fields as following format:

<FName> <LName> <Company> Missing Field/s:<> <>

example output:

eeee asdg gggg Missing Field/s: Salary Age
aara bdbm kkkk Missing Field/s: Salary

CAN ANYONE HELP ME PLEASE !!!!!!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
1
  #2
Oct 21st, 2009
Here is a start to your solution.
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2.  
  3. filename="/home/sk/daniweb/scripts/data.txt"
  4. exec<${filename}
  5. value=0
  6. declare -a arr
  7. while read line
  8. do
  9. varray=(`echo $line | awk '{ split($0, ulist, "|"); for(i=1; i<=11; i++) printf ulist[i] " "; }'`)
  10. echo "Array Length: " ${#varray[@]}
  11. done

That will read the input from your file in to an array inside of bash. Now you need to find the empty values and pull the header information.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 2
Reputation: e04047 is an unknown quantity at this point 
Solved Threads: 0
e04047 e04047 is offline Offline
Newbie Poster

FYI

 
0
  #3
Oct 21st, 2009
hi all,
I found the answer.Go through the link
==========================================
http://www.linuxquestions.org/questi...r-data-763384/
===========================================
Originally Posted by e04047 View Post
hi all,

I have this file [myfile.txt] with some user data.

example:
$cat myfile.txt
FName|LName|Gender|Company|Branch|Bday|Salary|Age
aaaa|bbbb|male|cccc|dddd|19900814|15000|20|
eeee|asdg|male|gggg|ksgu|19911216|||
aara|bdbm|male|kkkk|acke|19931018||23|
asad|kfjg|male|kkkc|gkgg|19921213|14000|24|
aera|bprb|male|cccc|pppp||15000|20|
.
.
. // and so on


So what I want to do is to take out (to a file) the missing fields as following format:

<FName> <LName> <Company> Missing Field/s:<> <>

example output:

eeee asdg gggg Missing Field/s: Salary Age
aara bdbm kkkk Missing Field/s: Salary

CAN ANYONE HELP ME PLEASE !!!!!!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #4
Oct 21st, 2009
Another crafty solution

Please mark this thread as solved as you have found an answer to your question and good luck!
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: natufor is an unknown quantity at this point 
Solved Threads: 0
natufor natufor is offline Offline
Newbie Poster
 
-2
  #5
28 Days Ago
thanks for sharing this information with us. its really very useful for me and all of us here.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC