Need help in splitting a line into fields in shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in splitting a line into fields in shell scripting
# 1  
Old 06-25-2008
Need help in splitting a line into fields in shell scripting

I have a line of more than 3000 bytes which will contain & as fields separator..I am using following awk command ..Its working but its not accepting the line more than 3000 bytes...Anyother alternate solution even in othe shell command also fine...

awk -F '&' '{for( i=1; i<=NF; i++ ) print $i}' file1

here file1 contains a line of more than 3000 bytes..

" HS_SYS=sys19&HS_ENV=lps&PRJ_NM=111111&DFU_TYPE=DFU&dfu_dataset=%2FHS_Data_00%2FDart%2FOut%2Fsys19%2F lps%2F400127.U&dfu_format_get=%2FHS_Appl_00%2FDatapull%2FDml%2Fdart_ufile.dml&dfc_file=%2FHS_Data_01 %2F400127.C&dfu_reform_xfr=nfields%3D16%260_proj%3DUPC_NUM%261_proj%3DPRDC_GRP_NUM%262_proj%3DMODULE _NUM%263_proj%3DUPC_D..................... "
# 2  
Old 06-25-2008
i) use an awk implementation which deals with long lines (e.g. GNU awk)
ii)
Code:
#!/bin/sh
for line in `cat file1`
do
  echo $line|tr \& \\n
done

(but your tr is likely to fail the same way your awk does)
# 3  
Old 06-25-2008
Code:
awk 1 RS=\& file


Code:
tr \& '\n'<file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting multiple fields of /usr/bin/id

Hi, Iv got the following input $id |grep uid uid=6090(dsiddiq) gid=1(staff) groups=4001(cdgrp) and Im using the below command to split the field to grab the numberical userid as well the alphabetical userid $id|awk -F'=' '{print $2}'|awk -F')' '{print $1}'|awk -F'(' '{print $1" "$2}'... (4 Replies)
Discussion started by: dsid
4 Replies

2. Shell Programming and Scripting

File splitting according to the length of the fields

Hi All, I have two files: 1> Data file 2> info file which has field lengths and start position. Is there a way to create a comma delimited file according to the fields length and start position. Data file : R-0000017611N-00000350001095ANZU01 A00000017611N000000350001095ANZU02... (11 Replies)
Discussion started by: nua7
11 Replies

3. Shell Programming and Scripting

Splitting a filed into multiple fields using awk

Hi, I have a tab delimited file as below: AWA Divi DD01 None 1 2 Room AC 01-MAY-15 31-OCT-15 OT 01-MAY-15 31-OCT-15 CF 01-MAY-15 31-OCT-15 AW0 Beach DD02 None 1 2 Double AC 01-MAY-15 31-OCT-15 AD 01-MAY-15 31-OCT-15 The number of columns(fields) after 7th field is not fixed and... (3 Replies)
Discussion started by: Bobby_2000
3 Replies

4. Shell Programming and Scripting

Help in splitting Sub Fields and compare with other field

Hi All, We are trying to pull out data from below table, the table contains four fields and out of which last two fields are having sub-fields with delimiter $, we want to identify number "1" position in the 3rd field and from 4th field need to extract the information from the same position. ... (4 Replies)
Discussion started by: rramkrishnas
4 Replies

5. Shell Programming and Scripting

Splitting a column in two separate fields

for making a summary I have a CSV file which is transformed to .DAT. I have an AWK file which is supposing to do the mapping of the DAT file. The code from the AWK file is the one below. The content of the DAT file looks like this (tab separated): ODT AGE CDT CO SEX TIME VALUE COMMENT ... (1 Reply)
Discussion started by: grikoss
1 Replies

6. Shell Programming and Scripting

Help with splitting fields

Hi. I want to put the first field to the end and the lines are of different number of fields. How should I do this with awk? Thanks. (3 Replies)
Discussion started by: dustinwang2003
3 Replies

7. Shell Programming and Scripting

Need one line scripting on Unix shell..help!!

Hi Experts, I need one line script for the below requirement. First it should check if a directory with todays date exist, and if not create it and move the PDF file to that directory. thanks in advance!!! (2 Replies)
Discussion started by: eeegopikannan
2 Replies

8. Shell Programming and Scripting

shell to find the count fields of each line

hi, i've many unload files with delimiter '|'. I'm trying to load them to the specific tables from those unl's. The problem here is, some unl's are corrupted. To be exact, some files doesnt seem to have the exact number of fields as in the table. So im trying to identify the corrupted... (6 Replies)
Discussion started by: dvah
6 Replies

9. Shell Programming and Scripting

End of Line in Shell Scripting

I have a file containing records seperated by delimiter '|'.A record is contained on 2 or 3 lines. Now I need a shell script which could write all records with in two '|' character in one line.....for example..... |R1........................R1 R1..........................R1... (2 Replies)
Discussion started by: 33junaid
2 Replies

10. Shell Programming and Scripting

who to deal with whole line in shell scripting

I have a problem in my HP Unix system , it is briefly : I have two files : Myfile and Script.sh : Myfile contain this lines : String1 string2 string3 string5 String1 string2 string3 string5 String1 string2 string3 string5 ... (2 Replies)
Discussion started by: KSA
2 Replies
Login or Register to Ask a Question