1. Extracting lines from a text file that match a certain criteria to another text file
Hi,
I am novice UNIX shell programmer and would like some help. I am
trying to write a shell script that will read a text file line by
line. The task is to extract lines from the text file that meet a set
of criteria to another text file.
An example of the text file, foo2, that I am using is shown below,
0,0,"NBSC",12,"24/02/2004 15:35:34","RD","2.2"
1,1,"ORG-UNIT-TYPE","C",1,"13/03/1997 17:24:49","PO"
1,2,"ORG-UNIT-TYPE","C",2,"13/03/1997 17:24:49","Client"
1,3,"ORG-UNIT-HIST","C",3,"13/03/1997 17:24:49","PON"
The task is to look at the 3rd field of each line, and extract the
whole line if the third field matches the criteria.
The criteria is to extract all lines that have the 3rd field set to
the value of "NBSC" to a separate text file.
Similarly to extract all lines, to another separate file, that have
the 3rd field set to the value of "ORG-UNIT-HIST".
All lines with 3rd field set to, "ORG-UNIT-TYPE" are to be ignored.
The psuedo code that I have come up with so far is shown below,
while read -r rec_type
do
NEXT=`echo ${rec_type} | cut -f 3 -d,`
if "${NEXT}" = "NBSC" then
write to text file1
else
if "${NEXT}" = "ORG-UNIT-HIST" then
write to text file 2
fi
fi
done < foo2
Any help or pointers would be greatly appreciated. Thanks in
antcipation
2. Mail Server drop dead
3. Script to extract portions of text from a text file
4. redhat 5.0 on 2nd partition
5. Command line command from text file
6. Internet and Local Security?
7. Extracting lines from inside a text file (question for sed expert)
8. Compiling for different kernel versions.
9. Extract different lines from a text file
10. ksh script to analyse data in a huge text file
11. Extracting text from a file in a shell script
12. need search to match line & extract previous line
13. Extracting multiple lines OR deleting multiple lines from a file using AWK