0

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 !!!!!!!!!!!!!!!

3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by natufor
1

Here is a start to your solution.

#!/bin/bash

filename="/home/sk/daniweb/scripts/data.txt"
exec<${filename}
value=0
declare -a arr
while read line
do
 varray=(`echo $line | awk '{ split($0, ulist, "|"); for(i=1; i<=11; i++) printf ulist[i] " "; }'`)
 echo "Array Length: " ${#varray[@]}
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.

Votes + Comments
:)
0

hi all,
I found the answer.Go through the link
==========================================
http://www.linuxquestions.org/questions/linux-newbie-8/shell-script-to-read-lines-in-a-text-file-and-filter-user-data-763384/
===========================================

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 !!!!!!!!!!!!!!!

0

Another crafty solution ;)

Please mark this thread as solved as you have found an answer to your question and good luck!

-2

thanks for sharing this information with us. its really very useful for me and all of us here.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.