Retrieve empty value in column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrieve empty value in column
# 1  
Old 04-19-2012
Retrieve empty value in column

hi guys,

how to retrieve "empty" value in column3 and column6 in the following text

Code:
$ cat myfile.txt
COL1              COL2                                COL3  COL4    COL5
val1              long_value_name_that_takes_space          value4  val5

                  COL6           COL7            COL8      COL9
                                 rather_longval  value8    val9

i want an output like:
Code:
COL1="val1"
COL2="long_value_name_that_takes_space"
COL3=""
COL4="value4"
COL5="val5"
COL6=""
COL7="rather_longval"
COL8="value8"
COL9="val9"

thank you very much Smilie
# 2  
Old 04-19-2012
Assumption is you have a fixed width file - adjust field widths in CSV as needed:

Code:
awk 'BEGIN { c=split("18,35,5,7,9,14,15,9", A, ",") }
{
   s=0
   for(p=1; p<=c;p++) {
       v=substr($0, s, A[p])
       s+=A[p]+1
       gsub(/ *$/,"",v)
       print "COL" p "=\"" v "\""
       }}' myfile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and retrieve the next Column.

Hi Guys, I have a File like below. FTOP,1|NOME,5|SERP,3 SERP,4|FTOP,7|POSE,4 Now, i am able to separate using multiple Delimiters in Awk. So,now when i search for FTOP, i need to retrieve the next column. In the above case, 1 7 Can somebody help as how to retrieve it. ... (2 Replies)
Discussion started by: mac4rfree
2 Replies

2. Shell Programming and Scripting

print non empty column/field value

I have below file 25-09-2012 24-09-2012 19-09-2012 31-07-2012 30-04-2012 30-03-2012 ASIAEXFVNV N/A CEU 4 DMIRSOA N/A CAS 2 2 2 DMIRSOA N/A MIDMT 2 NFIAL22 N/A HVNY 11 11 11 NFIAL22 N/A NYAL3 11 11 11 NFIAL22 N/A NYCN 11 11 11 ... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

3. Shell Programming and Scripting

If it is empty in column 5

Hi, I have a file with many columns. If it is empty in column 5 I want it to transfer the entire row into a new file. If there is a word (any word) in column 5 then I want it to be transfered into another separate file. e.g. input 1 2 3 4 5 2 3 4 5 File 1 1 2 3 4 5 File 2 2 3... (9 Replies)
Discussion started by: kylle345
9 Replies

4. Shell Programming and Scripting

Replace empty string on particular column

Hi I would like to replace empty string with a particluar value, any suggessions with awk ? my input file is not delimited with any delimiters input 52001073M8000000004567777 5200107 000000004567778 5200107 000000004567779 52001073M8000000004567789 Expected output... (5 Replies)
Discussion started by: selvankj
5 Replies

5. Shell Programming and Scripting

delete lines with empty second column

hi, I'd like to ask you if you can help me with such surely easy thing - I have some data and need to plot them. I have txt of data in two columns, tab separated, but some second columns are empty. like 1```` 2 1.2`` 3```` 2 4.44` 5````` 6.1```1 how can I erase all the lines... (2 Replies)
Discussion started by: bsco
2 Replies

6. Shell Programming and Scripting

sed/awk to retrieve max year in column

I am trying to retrieve that max 'year' in a text file that is delimited by tilde (~). It is the second column and the values may be in Char format (double quoted) and have duplicate values. Please help. (4 Replies)
Discussion started by: CKT_newbie88
4 Replies

7. Shell Programming and Scripting

have to retrieve the distinct values (not duplicate) from 2nd column and display

I have a text file names test2 with 3 columns as below . We have to retrieve the distinct values (not duplicate) from 2nd column and display. I have used the below command but giving some error. NS3303 NS CRAFT LTD NS3303 NS CHIRON VACCINES LTD NS3303 NS ALLIED MEDICARE LTD NS3303 NS... (16 Replies)
Discussion started by: shirdi
16 Replies

8. Shell Programming and Scripting

delete empty spaces at specific column

Hi All, If anybody could help me with my scenario here. I have a statement file. Example of some content: DATE DESC Debit Credit Total Rate 02-Jan-08 Lodgement 200.00 1200.00 2.51 14-Sep-07 Withdrawal 50.00 1000.00 ... (8 Replies)
Discussion started by: yonez
8 Replies

9. UNIX for Dummies Questions & Answers

(cont) Retrieve line from a file based on a value in specific column

HI, Your help was great: awk -F":" '$5 ~ /^P/{print }' file I would like to know what changes need to be done to this line code, so that I can put it in a shell script and call it as the example below. example: countries that start with chacater 'P' > country P Result: ... (0 Replies)
Discussion started by: efernandes
0 Replies

10. UNIX for Dummies Questions & Answers

Retrieve line from a file based on a value in specific column

Hi, I have a file that has several values seperated by ":" 2006:John:Student:Football:Portugal:Cinema 2006:James:Engineer:Basket:Poland:Theatre 2007:Lucy:Diver:Gymnastic:England:Music 2007:Smith:Plumber:Basket:Spain:Poker I need make a filter based on the 5th field to find countries that... (1 Reply)
Discussion started by: efernandes
1 Replies
Login or Register to Ask a Question