how to implement in one-line awk in a fixed file having no delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to implement in one-line awk in a fixed file having no delimiter
# 1  
Old 01-18-2011
how to implement in one-line awk in a fixed file having no delimiter

Hi,

I have a file a.txt having no delimiter.
I want to exclude the line which contains 435th character as 1 or 2 and redirect the rest of the lines to another file b.
Can you pls suggest how to do this in one liner awk.

Following is just one line of the input file a:-
Code:
120110116                                000001000000000001200000.00USD0000000001.2000135058492000094000000.00PL 000.150000B  000000000000.00   0105.00000.000
0002011011820110121MODE0               D4028                  27385       JP31368000044028 6466866          FJT140280               COMNIVBIHARA SANGYO Y50
             JPY                                     ABC000000000000.00Eabcdend                                                              VICVBERTTN0093.000
053.000000.00                20110118      05:57:31      000.00000010185450    TFLOW    NBD   NNF    CHASNEAB MODFAN CHABD CDBV as agdnt (NE180 ESCROW)
                             UTCHBS
                                                                                                                ABC.BADKS NMRSJPJT                 AD-SD5213
                                                                                                                       NIMIPA
                                                                    ABC.BCDSS MHCBJPJ2                 0000380
                                                                           MIZUHO                                            000.150000000001200000.0000000100
0000  VICKRRTT                         NNNN                                     NNN000000000000.00N0000N                               00         000000000000
.00                                                                                                                                                0000000000.
0000000000000001000000                           000.000000000.000000000.000000000000000000.00000000000000.00000000000000.00         000000000000.00 000000000
0.000000000000000000.00000000000000.000000000000.000000000000000000.00000000000000.00000000000000.00000000000000.00000000000000.0020110121000000000000.00Y0000
01136432.33              NY10185450        N0900080.00
                                                                                                0000000001.20000000000000000.0000000T000000000000.000000010000
00.00000001000000.00000001000000.00ABC                                            0100.00                     0000000000


Last edited by Franklin52; 01-18-2011 at 03:20 AM.. Reason: Please use code tags
# 2  
Old 01-18-2011
Try:
Code:
awk '$435~/[12]/{print>f;next}1' FS= f=new infile > old

# 3  
Old 01-18-2011
Scrutinizer

Can you explain the bit of command, didn't understand

f=new

and why 1 was used
# 4  
Old 01-18-2011
f=new means give variable f the value "new" so that records that contain 1 or 2 at position 435 are written to the file "new"
1 means {print $0}
# 5  
Old 01-18-2011
thanks a lot for the reply.

I did not understnad the command fully.
what are f,new,infile,old ?

i have tried taking infile as input file and old as the output file,it was not working.

Can you please simplify the command or can you pls give the sed command which serve this purpose,it would be also great.

Thanks.

Last edited by millan; 01-18-2011 at 04:43 AM.. Reason: as the command was not working
# 6  
Old 01-18-2011
Hi Millan, if the command works as intended, the records that contain 1 or 2 at position 435 get written to the file "new" and the rest of the records get written to the file "old" . "infile" is the name of the input file that contains all the records..

S.
# 7  
Old 01-18-2011
I am so sorry to say that this command is not working.

Can you pls give any other approach or any sed command.

assuming my input file name is 'infile' which contains all the data and
output file name is 'outfile' which contains only those data which does not contain 435th character as 1 or 2.

and also i appreciate your prompt reply.

Thanks,
Millan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

Hi Forum. I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type. The main command in the script is: awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies

2. Shell Programming and Scripting

Join the line on delimiter using sed/awk in UNIX

I've input as , abcd| ef 123456| 78| 90 Desired output as, abcdef 1234567890 Anyone please give the solution. (5 Replies)
Discussion started by: jinixvimal
5 Replies

3. Red Hat

Converting fixed width file to pipe delimiter in Linux(red-hat)

Hi, I am facing a typical scenario for AWK command . In HP- UNIX is behave as expected but in red hat linux same awk code is not give the same result. The below code is for convert the fixed width file to pipe delimiter file in HP-unix server. awk code: #!/bin/awk -f NR!=1... (11 Replies)
Discussion started by: brij_abhi
11 Replies

4. Shell Programming and Scripting

Adding delimiter to a fixed pattern of date

I have a text file as below: jan16201413:17PM jan1620143:17PM jan1620143:17PM jan1620143:17PM jan1620143:17PM I want to add a delimeter which will be space to the date part as below: jan 16 2014 13:17 PM jan 16 2014 3:17 PM jan 16 2014 3:17 PM jan 16 2014 3:17 PM jan 16... (13 Replies)
Discussion started by: Sharma331
13 Replies

5. Shell Programming and Scripting

Need next line as a space delimiter in awk

Hi,Below is the output for p3fi_dev services 1/app/oracle> . ./oraprofile_p3fi_dev p3fi_dev_01 (P):/devoragridcn_01/app/oracle> srvctl config service -d p3fi_dev p3fi_p3fi_dev.world PREF: p3fi_dev_01 AVAIL: p3fi_dev_02 pplnet_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02 nexus_p3fidev PREF:... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

6. Shell Programming and Scripting

Implement in one line sed or awk having no delimiter and file size is huge

I have file which contains around 5000 lines. The lines are fixed legth but having no delimiter.Each line line contains nearly 3000 characters. I want to delete the lines a> if it starts with 1 and if 576th postion is a digit i,e 0-9 or b> if it starts with 0 or 9(i,e header and footer) ... (4 Replies)
Discussion started by: millan
4 Replies

7. Shell Programming and Scripting

search for a string without fixed delimiter in the line

Hi Need your help to assign the string to a variable from a line which has no fixed delimter in unix. for example , my file contains Name="report"" File Name one="test1" File Name two="test2" now how do I read report , test1 and test2 ? var1=report var2=test1 var3=test2 ... (1 Reply)
Discussion started by: rashmisb
1 Replies

8. UNIX for Advanced & Expert Users

Insert Delimiter at fixed locations in a flat file

Hi Can somebody help me with solution for this PLEASE? I have a flat file and need to insert delimiters at fixed positions in all the lines so that I can easily convert into EXCEL with columns defined as per their width. For Example Here is the file { kkjhdhal sdfewss sdtereetyw... (7 Replies)
Discussion started by: jd_mca
7 Replies

9. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

10. Shell Programming and Scripting

adding delimiter to a fixed width file

Hi , I have a file : CSCH74000.00 CSCH74000.00 CSCH74100.00 CSCH74000.00 CSCH74100.00 CSCH74000.00 CSCH74000.00 CSCH74100.00 CSCH74100.00 CSCH74100.00 I have to put a delimiter( say comma) in between after 6th character: CSCH74,000.00 CSCH74,000.00 CSCH74,100.00 (2 Replies)
Discussion started by: sumeet
2 Replies
Login or Register to Ask a Question