filter out all the records which are having space in the 8th filed of my file

I have a file which is having fileds separtaed by delimiter.

Ex:

C;4498;qwa;cghy;;;;40;;222122
C;4498;sample;city;;;;34 2;;222123
C;4498;qwe;xcbv;;;;34-2;;222124
C;4498;jj;sffz;;;;41;;222120
C;4498;eert;qwq;;;;34 A;;222125
C;4498;jj;szxzzd;;;;34;;222127

out of these records I want to write those reocrds whcih
have alphanumeric chartacters(ex : space,allphabets,'A','B' etc)
at 8th filed to one file( i.e. filter out all the records which are having space or - as 34 A,34-A in the 8th filed of my file )and remaing to another file.

how to do this using awk or something else in UNIX?

so my final out files should be like this

1st file

C;4498;jj;cghy;;;;40;;222122
C;4498;qwa;sffz;;;;41;;222120
C;4498;jj;szxzzd;;;;34;;222127

2nd file

C;4498;sample;city;;;;34 2;;222123
C;4498;qwe;xcbv;;;;34-2;;222124
C;4498;eert;qwq;;;;34 A;;222125

You can use cut command as follows:
# cut -b8 <filename>

This will return the character at 8th position. Then you can grep for those records which do not match the expression.

Hope this helps :slight_smile:

#create a file something like 8thfield.txt with below mater
C;4498;qwa;cghy;;;;40;;222122
C;4498;sample;city;;;;34 2;;222123
C;4498;qwe;xcbv;;;;34-2;;222124
C;4498;jj;sffz;;;;41;;222120
C;4498;eert;qwq;;;;34 A;;222125
C;4498;jj;szxzzd;;;;34;;222127

#execute this command to separate the lines which contains 8th field as space or hypen
awk -F";" '{print $8}' 8thfield.txt | egrep " |\-" | xargs -i egrep "{}" 8thfield.txt > file1.txt

#execute this command to ignore the lines which contains 8th field as space or hypen
grep -v "`cat file1.txt`" 8thfield.txt

cat file1.txt
C;4498;sample;city;;;;34 2;;222123
C;4498;qwe;xcbv;;;;34-2;;222124
C;4498;eert;qwq;;;;34 A;;222125

cat file2.txt
C;4498;qwa;cghy;;;;40;;222122
C;4498;jj;sffz;;;;41;;222120
C;4498;jj;szxzzd;;;;34;;222127

Thanks,
Phani Kumar

 
awk -F";" '$8 !~ /[-A-Z ]/  { print $0 >>"proper.txt";next } { print $0 >>"improper.txt"} ' File_name.txt