Text Conversion in Column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text Conversion in Column
# 8  
Old 09-23-2014
Quote:
Originally Posted by gc_sw
thanks SriniShoo but:

Code:
awk 'BEGIN{a[1] = "RED"; a[2] = "BLUE"; a[3] = "YELLOW"; a[5] = "ORANGE"} NR>1 {$6 = a[$6]}1' file
awk: syntax error near line 1
awk: bailing out near line 1

how to add another conditions to:
Code:
awk 'BEGIN{OFS=FS="\t"}$5==1{$5="RED"}{print}' /var/tmp/db.txt > /var/tmp/db_new.txt

If you're running this on a Solaris system, change awk in SriniShoo's suggestion to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk. But, if the code you had shown us before produced the output you said it did, this isn't your problem?????
# 9  
Old 09-23-2014
sorry Don;
my all values are \t seperated and my code was:

Code:
awk 'BEGIN{OFS=FS="\t"}$6==1{$6="RED"}{print}' /var/tmp/db.txt > /var/tmp/db_new.txt

and it worked. but I just wonder how to add else if conditions into my command?

Last edited by Don Cragun; 09-23-2014 at 05:55 AM.. Reason: Fix COLOR tags.
# 10  
Old 09-23-2014
Next time, please save us all a lot of time and aggravation by telling us what OS and shell you're using and showing us sample input and output that matches the data you want to process.

A slightly modified version of SriniShoo's code should do what you want:
Code:
/usr/xpg4/bin/awk 'BEGIN{FS = OFS = "\t"; a[1] = "RED"; a[2] = "BLUE"; a[3] = "YELLOW"; a[5] = "ORANGE"} NR>1 {$6 = a[$6]}1' file

This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 09-23-2014
thank you Don.
it is working now..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Conversion of rows to columns using awk based om column value

HI, My Input file data is dn:adcfgeneral id:13343 Name:xxxxxx Password:iutyerwuitywue wpuwt tuiytruityrutyrwtyrwp dn:cdferwjyyyy id:3875 Name:yyyy Password :hgfdsjkfhdsfkdlshf dshfkldshfdklsfh interset:uiuiufj My output should be ... (6 Replies)
Discussion started by: dineshaila
6 Replies

2. Shell Programming and Scripting

Conversion if 1st column is match (awk '{s+=$1} END

Hi im trying to add numbers, got no problem with it im using awk '{s+=$1} END {print s, "MB"}', but what if the numbers are like mention below. who will i add them 2000 KB 1 MB Answer: 2001 Desired: 2000 KB 1 MB Answer: 3000 (4 Replies)
Discussion started by: invinzin21
4 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Uneven column to row conversion

Hi Unix Forum, I have a relatively easy question i suppose for which, however, until now i could not find a solution. I am working with a program that will give me an output file similar to the following: A 1 2 3 4 B 1 2 3 4 C 1 (9 Replies)
Discussion started by: Leander
9 Replies

4. Solaris

Rows to column conversion in Solaris

i am using the command pkginfo -l | /usr/xpg4/bin/grep -e 'VENDOR' -e 'NAME' -e 'VERSION' >> /tmp/test1.txt in order to get name,vendor and version of the applications installed on Solaris machine.The output stored in test1.txt in as shown below: NAME: Solaris Zones (Usr) VERSION: ... (4 Replies)
Discussion started by: omkar.jadhav
4 Replies

5. Shell Programming and Scripting

Row to Column conversion?

I have a text file with the geneIds separated by space in each line. The number Ids in lines are different. The file is like: abc qwe tyu ghj jkl dfg sdf cvb sdk fgh tyu uio iop tyu rty eru wer rty iop asd sdf dfg fgh zxc I want to format the file like: abc qwe tyu ghj jkl ... (7 Replies)
Discussion started by: sammy777
7 Replies

6. Shell Programming and Scripting

Lines to Column conversion

Hi All, I have a sample file with content: # cat test1.txt mahesh suresh anil # I need to get it like this: m s a a u n h r i e e l s s h h Basically row to column and column to row. I am trying to use this: while read line do echo $line | fold -bw 1 (2 Replies)
Discussion started by: digitalrg
2 Replies

7. Shell Programming and Scripting

text to csv conversion

Thank u every body ......just need a help so that a text file needs to be converted into CSV............. my log file is as follows Host scsi3: usb-storage Vendor: Maxtor Product: OneTouch III Serial Number: 044303E5 Protocol: Transparent SCSI Transport: Bulk ... (4 Replies)
Discussion started by: tangotango
4 Replies

8. UNIX for Dummies Questions & Answers

converting unique identifiers in a column using conversion file

Hello, I often have this problem: I have a file with a column of unique identifiers e.g. file1 below has an id column and data column/columns with p rows: cat data1 dog data2 cow data3 . . . elephant datap-1 horse datap and I have a conversion file,file2, with n<p rows... (4 Replies)
Discussion started by: peanuts48
4 Replies

9. Shell Programming and Scripting

Text to xlsx conversion

Hi Guys, The code snippet below is working fine with xls 2003 but the same is not working in xlsx 2007. Can someone please help. #Convert .txt file format to .xls format awk 'BEGIN{ FS="|" cols=8 print "<HTML><style type=\"text/css\">td{mso-number-format:\"\@\"}</style><BODY><TABLE... (1 Reply)
Discussion started by: icefish
1 Replies

10. Shell Programming and Scripting

column to row conversion with additional pattern

Hi there, I've an input file1 as follows: 1001 1002 1003 1004 1005 I would like to have an output file2 as follows: Numbers are 1001/ 1002/ 1003/ 1004/ 1005/ Any help is appreciated. (2 Replies)
Discussion started by: kbirde
2 Replies
Login or Register to Ask a Question