awking two columns based on symbols


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awking two columns based on symbols
# 1  
Old 03-02-2009
awking two columns based on symbols

The input file has 3 columns. the first column with low values second with bigger.If the symbol is - in third column the numbers have to change the least in column1 and highest in col2.
Input
col1 col2 col3
1 2 +
2 3 -
3 4 +
5 6 -

Output
col1 col2 col3
1 2 +
3 2 -
3 4 +
6 5 -
The code I'm trying to using is this but it is converting all numbers into highest in col1 and lowest in col2
Help me out guys

sed's/\t/g' file1|awk -F"\t" {if($2>$1) {print $2,"\t",$1} else {print$1,"\t",$2}}'
# 2  
Old 03-02-2009
Like this?

Code:
awk '$3 == "-" {print $2,$1,$3} $3 == "+" {print}' file

# 3  
Old 03-02-2009
hi

thanx alot its working
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Transpose a sequence of symbols from row to one columns (no separators))

Hi all, I have a data file. It contains one header line followed by a new line which is one row of different characters without separators (charahters can be dots, dash, capital and small letters). What I need is ignoring header line to transpose these characters so they form a column. So, from... (4 Replies)
Discussion started by: kush
4 Replies

2. Shell Programming and Scripting

Awking binary data

i have a binary data that has some text in it. what i want to do is, i want to grab just piece of information from the binary. but when i run my awk on it, it returns nothing. awk -F"MYINFO=" '{print $2}' mybinary however, when i install gawk, then try again, it works. i would prefer... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

Awking custom output

i have data that can look like this: echo "Master_Item_Service_is_down=0_njava_lang_NoClassDefFoundError=0_njava_lang_OutOfMemoryError=1_nemxCommonAppInitialization__Error_while_initializing=0_nINFO__Stopping_Coyote_HTTP_1_1_on_http_8080=7_nThe_file_or_directory_is_corrupted_and_unreadable=0_n" ... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

Add new columns based on existing columns

Hi all, I am kind of stuck with printing my desired output. Please help me if you know how it can work. My input file(tab separated): NW_0068.1 41,16 100,900 NW_0699.1 4,2,19 200,700,80 My Output file (desired): NW_0068.1 41,16 100,900 100 - 141 NW_0068.1 41,16 100,900 ... (3 Replies)
Discussion started by: sam_2921
3 Replies

5. Shell Programming and Scripting

name the column based on symbols in another column

Hi if the input columns (both 2nd and 3rd) are either + or - give the name 1stname. if the 2nd one + and 3rd one - give the name 2ndname and if the 2nd one - and 3rd one + give the name 3rd one as showed in output Thanx input x + + some values in other columns t - - ..... t + ... (7 Replies)
Discussion started by: repinementer
7 Replies

6. Shell Programming and Scripting

Change names in a column based on the symbols in another column

If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output). Thanx input1 1 a aaaaa + 2 b bbbbb + 3 c ccccc + 4 d ddddd + 5 e eeeee + 6 f xxxxx + 8 h hhhhh +... (8 Replies)
Discussion started by: repinementer
8 Replies

7. Shell Programming and Scripting

awking two columns

Hey ppl I have two columns with random values. i need to insert the 1st row of the first column with the highest number of the two rows in the first column and vice versa. some thing like this. I'm sorry If my question is unclear...:rolleyes: input col1 col2 12...11 11...14 34...45... (11 Replies)
Discussion started by: sophiesophie
11 Replies

8. Shell Programming and Scripting

Help with awking

Hi... How does awk or sed or even grep extract the following string out of my text file?. '"${ETL_VW_SCHEMA}"'.IATA_STN_TZ_UTC_LCL_CONV_CV '"${ETL_VW_SCHEMA}"'.CO '"${ETL_VW_SCHEMA}"'.TEST_CO I just need to extract the second entry which means I need to let awk know I am just searching for... (5 Replies)
Discussion started by: anduzzi
5 Replies

9. Shell Programming and Scripting

Awking

Could someone find out wht exactly is goin wrong in the following awk: awk '/${EDW_DB_SCHEMA}.WRKR/ || !/otable/&&/${EDW_DB_SCHEMA}.WRKR/ || !/db-ter-load-data/&&/${EDW_DB_SCHEMA}.WRKR/' <my_graph>.ksh Basically, I am trying to achieve: Find out the occurence of WRKR table in <my_graph>.ksh... (3 Replies)
Discussion started by: anduzzi
3 Replies

10. Shell Programming and Scripting

Sorting based on columns

Hi, I want a list of entries in 3 space delimited columns. I want to sort entries based on the very first column. Rows can't be changed. For example: If I have... Abc Abc Acc Bca Bda Bdd Cab Cab Cbc Dbc Dca Dda Abc Abc Acc the output should be... Abc Abc Acc Abc Abc Acc Bca... (7 Replies)
Discussion started by: MobileUser
7 Replies
Login or Register to Ask a Question