| | |
Shell script to read lines in a text file and filter user data
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 2
Reputation:
Solved Threads: 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 !!!!!!!!!!!!!!!
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 !!!!!!!!!!!!!!!
1
#2 Oct 21st, 2009
Here is a start to your solution.
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.
Shell Scripting Syntax (Toggle Plain Text)
#!/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.
•
•
Join Date: Aug 2008
Posts: 2
Reputation:
Solved Threads: 0
hi all,
I found the answer.Go through the link
==========================================
http://www.linuxquestions.org/questi...r-data-763384/
===========================================
I found the answer.Go through the link
==========================================
http://www.linuxquestions.org/questi...r-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
#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!

Please mark this thread as solved as you have found an answer to your question and good luck!
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
-2
#5 28 Days Ago
thanks for sharing this information with us. its really very useful for me and all of us here.
![]() |
Similar Threads
- Counting lines in a text file and further operations (C++)
- read line of text from file into array (C++)
- Script to Remove duplicate lines from a text file. (Perl)
- read-delete lines from a text file (PHP)
- writing students data to a text file (Assembly)
- how to remove a number of lines from a text file ? (Python)
- Replace text in a file (Shell Scripting)
- how do i read the last line of a text file? (Python)
Other Threads in the Shell Scripting Forum
- Previous Thread: Awk Problems
- Next Thread: Counter
| Thread Tools | Search this Thread |






