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
# 8  
Old 09-19-2015
Well, you have a 2A instead of the 2B ...

Howsoever, try
Code:
awk -F',' '
FNR>1   {TMP=substr($1,1,5) "_" substr($3,19,20)
         print $1,$2,TMP $4 ($5?OFS TMP $5:"")}
' OFS="," file
RXOCF-101,BTS INTERNAL,RXOCF_2A53,RXOCF_2A58
RXOCF-101,BTS INTERNAL,RXOCF_2B24
RXOCF-101,BTS INTERNAL,RXOCF_2A33
RXOCF-101,BTS INTERNAL,RXOCF_2D57
RXOCF-102,OPERATOR CONDITION,RXOCF_2B

This User Gave Thanks to RudiC For This Post:
# 9  
Old 09-19-2015
Sorry, corrected row 2 now.

---------- Post updated at 02:47 AM ---------- Previous update was at 02:35 AM ----------

Code:
cat file
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,53,58
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2B,24
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,33  
RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2D,57  
RXOCF-102,OPERATOR CONDITION FAULT CODES CLASS 2B

Code:
awk -F',' 'FNR>1 {TMP=substr($1,1,5) "_" substr($3,19,20) print $1,$2,TMP $4 ($5?OFS TMP $5:"")}'
awk: syntax error near line 1
awk: illegal statement near line 1

It's giving me above error
# 10  
Old 09-19-2015
What's your OS and awk version?

---------- Post updated at 23:50 ---------- Previous update was at 23:48 ----------

Independent of OS and awk, if you concatenate lines, don't forget a ; as the command separator. Why didn't you test the script as given?

Last edited by RudiC; 09-19-2015 at 06:59 PM..
# 11  
Old 09-19-2015
I'm using Solaris 5.10.
Where to put ; ?
I don't see ; in your script

---------- Post updated at 03:05 AM ---------- Previous update was at 03:02 AM ----------

Code:
 awk -F',' '
> FNR>1   {TMP=substr($1,1,5) "_" substr($3,19,20)
>          print $1,$2,TMP $4 ($5?OFS TMP $5:"")}
> ' OFS="," file
awk: syntax error near line 3
awk: illegal statement near line 3

# 12  
Old 09-19-2015
c.f. Don Cragun:
Quote:
If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk .
This User Gave Thanks to RudiC For This Post:
# 13  
Old 09-19-2015
Thankyou Smilie nawk worked for me. Thanks for the help.
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