awk print columns which are not null

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk print columns which are not null
# 1  
Old 09-19-2015
Error awk print columns which are not null

I am working on a file with several columns as below


By using awk I'm printing the output like this
awk -F',' '{print $1,$2,substr($1,1,5)"_"substr($3,19,20)$4,substr($1,1,5)"_"substr($3,19,20)$5' OFS="," file.txt

The output comes like this


I want to skip the columns whihc have null code or nothing in the code column. Please help to get this desired output
Moderator's Comments:
Mod Comment Please use CODE tags for sample input and output as well as for code segments.

Last edited by Don Cragun; 09-19-2015 at 06:53 PM.. Reason: Add more CODE tags.
# 2  
Old 09-19-2015
Not sure I understand. What columns are missing? How does 2A53 get into output line 2? And 2A into line 5?
# 3  
Old 09-19-2015
I am printing Col1,Col2,Partof(Col1)_Partof(Col2)Col4

if Col4 is null then the output is just like as above in my row 3,4 and 5 (last columns with no code)

2A53 comes from:

2A is part of Col3 and 53 is my Col4 (Concatenated both)
# 4  
Old 09-19-2015
Not in line 2.

---------- Post updated at 23:20 ---------- Previous update was at 23:19 ----------

And - what about $6?
# 5  
Old 09-19-2015
Don't have $6 in original file. Corrected it. Printing till $5 now
# 6  
Old 09-19-2015
What about the output in line 2?

---------- Post updated at 23:31 ---------- Previous update was at 23:30 ----------

A bit more care when specifying the problem would help us help you.
# 7  
Old 09-19-2015
In line 2, "2B" is the substring of column 3 and "24" comes from column 4.
It's the concatenation of substring of column 1, substring of column 3 and with code in column 4
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies

2. Shell Programming and Scripting

awk print columns and variable

Hi, Can anyone help with the below please? I have written some code which takes an input file, and and prints the contents out to a new file - it then loops round and prints the same columns, but increments the ID column by 1 each time. Input file; NAME,1,15-Dec-15, NAME,1,21-Dec-15,... (9 Replies)
Discussion started by: Ads89
9 Replies

3. Shell Programming and Scripting

Awk: is it possible to print into multiple columns?

Hi guys, I have hundreds file like this, here I only show two of them: file 1 feco4_s_BB95.log ZE_1=-1717.5206260 feco4_t_BB95.log ZE_1=-1717.5169250 feco5_s_BB95.log ZE_1=-1830.9322060... (11 Replies)
Discussion started by: liuzhencc
11 Replies

4. Shell Programming and Scripting

Awk print all columns in delimited file

text file example 1,222222222222,333,444444444444444 111111111,22,33333333,444 desired output 1 222222222222 333 444444444444444 111111111 22 33333333 444I have a delimeted file which I want to print in a table like format. The... (10 Replies)
Discussion started by: Calypso
10 Replies

5. Shell Programming and Scripting

Awk script to replace null columns with blank

I have a file with contents "08011"||20080812 "23348"|20080827|20080924 "23387"|20080829|20080915 "23581"|20081003|20081028 "23748"|20081017|20090114 "24095"|20080919|20081013 "24105"|20070723|20070801 "24118"|20080806|20081013 "24165"|20080820|20080912 "24221"|20080908|20080929 i... (3 Replies)
Discussion started by: sonam273
3 Replies

6. Shell Programming and Scripting

awk: print columns depending on their number

hi guys, i have the following problem: i have a matrix with 3 columns and over 450 rows like this: 0.0165 0.0151 0.0230 0.0143 0.0153 0.0134 0.0135 0.0123 0.0195 0.0173 0.0153 0.0182 i now want to calculate the average of every line and divide every element of this... (1 Reply)
Discussion started by: waddle
1 Replies

7. Shell Programming and Scripting

Removing columns from awk '{ print $0 }'

I have a one-line command, lsusb | awk '{ $1=""; $2=""; $3=""; $4=""; $5=""; $6=""; print $0 }' It works, and gives the results I expect, I was just wondering if I am missing some easier way to nullify the first 6 column variables? Something like, lsusb | awk '{ $(1-6)=""; print $0 }' But... (10 Replies)
Discussion started by: AlphaLexman
10 Replies

8. Shell Programming and Scripting

awk command to print multiple columns

Hello Team, I have written following command which is giving output is as shown below. bash-3.00$ grep -i startup catalina.out | tail +2 | sed -n 1p | awk -F" " '{ for (x=1; x<=5; x++) { printf"%s\n", $x } }' Dec 19, 2010 3:28:39 PM bash-3.00$ I would like to modify above command to... (2 Replies)
Discussion started by: coolguyamy
2 Replies

9. Shell Programming and Scripting

using awk to print some columns of a file

Hi, i have a file with content 00:01:20.613 'integer32' 459254 00:01:34.158 459556 00:01:36.626 'integer32' 459255 and i want to print only output as below 00:01:20.613 459254 00:01:34.158 459556 00:01:36.626 459255 i dont want the word 'integer32' which is the second column. i... (2 Replies)
Discussion started by: dealerso
2 Replies

10. Shell Programming and Scripting

cannot print the columns i want with awk.

hi friends! i have a script where a execute a veritas command, available_media wich retrieves me a list of tapes .lst then i execute cat /tmp/listtapes.lst | grep -v VL |sed '/^$/d'|awk -F, '{print $1, $3, $4, $9} ' > /tmp/media1.lst but it prints all the columns instead of the four... (3 Replies)
Discussion started by: pabloli150
3 Replies
Login or Register to Ask a Question

Featured Tech Videos