validating data in columns and writing them to new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting validating data in columns and writing them to new file
# 1  
Old 10-23-2012
Data validating data in columns and writing them to new file

I have a file that contains records in the below format:

Code:
23857250998423948239482348239580923682396829682398094823049823948
23492780582305829852095820958293582093585823095892386293583203248
23482038509825098230958235234230502958205983958235820358205892095
396873950075037609888888000000XT035890980820000000000000000000000
503689234986246723490502389593XT824959500305000000000000000000000
234235248649368345435349689459XT834534845900005289234994939459300
423852349234943923495655494969XT240895300503030300000000000000000
2352463574767845656534634634643XT45235246537457846868686474674577

I want to check for X & T in column's 31 & 32 and write only those records to new file.

the new file should have only 4 records:
Code:
396873950075037609888888000000XT035890980820000000000000000000000
503689234986246723490502389593XT824959500305000000000000000000000
234235248649368345435349689459XT834534845900005289234994939459300
423852349234943923495655494969XT240895300503030300000000000000000


Last edited by Scott; 10-23-2012 at 04:47 PM.. Reason: Code tags
# 2  
Old 10-23-2012
If there are line feeds between records, it seems a pretty simple grep/regex problem! Not homework, I hope!
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 10-23-2012
Code:
perl -F"" -alne '{($F[30]." ".$F[31])==("X T")?print:next;}' input_file

This User Gave Thanks to msabhi For This Post:
# 4  
Old 10-23-2012
Quote:
Originally Posted by msabhi
Code:
perl -F"" -alne '{($F[30]." ".$F[31])==("X T")?print:next;}' input_file

Thank you! Can't use perl, only in unix please
# 5  
Old 10-23-2012
Code:
awk -F "" '$31=="X" && $32=="T"'  input_file

This User Gave Thanks to msabhi For This Post:
# 6  
Old 10-23-2012
Code:
grep 'XT' filename > newfilename

# 7  
Old 10-23-2012
Well, PERL, awk, sed, grep are all apps, but PERL is a full language (in which people shell out a lot!) not native to all UNIX systems. I like sed's moderately expanded regex:
Code:
sed '^.\{30\}XP/!d' infile >outfile

This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing output to a file in columns

Hi I am trying to write output to a file in columns I have file in the follwoing: # cat file abc def # I am trying to write next output as like # cat file abc 123 def 345 # :mad: (6 Replies)
Discussion started by: Priya Amaresh
6 Replies

2. Shell Programming and Scripting

awk error - validating strings in columns

can someone please help me fix this command: somecommand.sh | awk -F"---" 'BEGIN{count=0} /P/ && /ERROR/ {if (($3 ~ /^P$/) && ($6 ~ /ERROR/)) {print; count++ }END { print count } ;}' basically, what i'm attempting to do here is print all the matching lines, then, at the end, print the total... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Writing input data in file

I am having an input file for eg. file.txt which contains pipe delimited rows file.txt: xx|yyy|zz|12|3|aaaaa|..... yy|zz|1|3|4|xxxxx|....... . . . i want the above file name to be transformed into another file with giving input from the user and replacing the corresponding fields based... (5 Replies)
Discussion started by: rohit_shinez
5 Replies

4. Shell Programming and Scripting

Comparing Columns and writing a new file

I have a table with one column File1.txt 1 2 3 4 5 6 7 8 9 10 Another table with two columns; This has got a subset of entries from File 1 but not unique because they have differing values in col 2. File2.txt 1 a 2 d 2 f 6 r 6 e (3 Replies)
Discussion started by: cs_novice
3 Replies

5. Shell Programming and Scripting

Problem in writing the data to a file in one row

Hi All I am reading data from the database and writing to temporary file in the below format. 1=XP|external_component|com.adp.meetingalertemail.processing.MeetingAlertEmail|EMAILALERTPUSH|32|4#XP |classpath|/usr/home/dfusr/lib/xalan.jar: /usr/home/dfusr/lib/xerces.jar: ... (2 Replies)
Discussion started by: rajeshorpu
2 Replies

6. Programming

writing binary/struct data to file

I am trying to write binary data to a file. My program below: #include <stdlib.h> #include <stdio.h> struct tinner { int j; int k; }; struct touter { int i; struct tinner *inner; }; int main() { struct touter data; data.i = 10; struct tinner... (4 Replies)
Discussion started by: radiatejava
4 Replies

7. Shell Programming and Scripting

AWK Help- Writing Data into a File

Hi All, I need to maintain a AUDIT file in system for every incoming and outgoing file. For this i am trying to append a record by using the AWK every time the file arriving. I have used the code as below. AWK '{print "FILENAME IS", $1,"DATE IS", $2}' >> AUDITFILE.txt $1 and $2 are global... (1 Reply)
Discussion started by: Raamc
1 Replies

8. UNIX for Dummies Questions & Answers

Validating XSL sheet data in Unix Data file

Dear All, Need your help. In my day to day activities I have to validate/search Excel Sheet data (eg.say Application No. 0066782345) data into the Unix environment file whether the same data is present in that file or not. There are hundreds of records coming in excel file and I am doing grep... (1 Reply)
Discussion started by: ravijunghare
1 Replies

9. Shell Programming and Scripting

validating data

I have a file like the following aaaaa00005bbbbb aaaaa00108bbbbb The code "00005" and "00108" need to be validated and the list of valid codes are stored in a database. While I loop through the file, should call a sql statement for every records to do the validation? or is... (1 Reply)
Discussion started by: joanneho
1 Replies
Login or Register to Ask a Question