awking two columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awking two columns
# 1  
Old 02-26-2009
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...Smilie

input
col1 col2
12...11
11...14
34...45
14...67
31...21

output
col1 col2
12...11
14...11
45...34
67...14
31...21
# 2  
Old 02-26-2009
Not able to understand..make it clear plz....?

Thanks
Sha
# 3  
Old 02-26-2009
its about the two values of two columns
I need to make the first column values will be higher compared to the subsequent column 2 values

11 ..12 to 12.. 11
# 4  
Old 02-26-2009
Bug

use below one ...hope this should work..

sed 's/\.\.\./,/g' inputfile |awk -F"," '{if($2 > $1) {print $2,$1} else {print $1,$2}}'

output:
12 11
14 11
45 34
67 14
31 21

if you want the same format output then use below one:

sed 's/\.\.\./,/g' out.lst|awk -F"," 'OFS="..." {if($2 > $1) {print $2,$1} else {print $1,$2}}'

output:
12...11
14...11
45...34
67...14
31...21


Thanks
Sha
# 5  
Old 02-26-2009
sed 's/\.\.\./,/g'

wht this mean
# 6  
Old 02-26-2009
In your input file ..you have used delimeter..something like this "..."
so before i proceed with comparing column to make it easy myself...i changed delimeter from "..." to ","

Thanks
Sha
# 7  
Old 02-26-2009
actually I have tab in between two file and I need result with tab

thanx
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Grepping or awking multiple lines in a file - regex

data.txt: hellohellohello mellomello1mello tellotellotellotello bellobellowbellow vellow My attempts: egrep ".*mello1\n.*bellow" data.txt awk '/.*mello1.*\nbellow/' data.txt how can i search for patterns that are on different lines using simple egrep or awk? i only want the... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

Awking string only 6 character long and providing a count

Morning Guys, I am attempting to awk a file which strings in the file is only 6 characters long and not more. Currently it is counting every line and giving a count of 59, but it should be 57 (not including the long baracode - 004705CIM*****) " awk '/./ {cnt++} END {print cnt}'... (11 Replies)
Discussion started by: Junes
11 Replies

5. Shell Programming and Scripting

Help awking a 'head -1 file.txt' input

Hi there, my ksh script collects a procstack trace for a particular pid and then greps it by a transaction id to find out the pthread ID: ---------- tid# 1876087 (pthread ID: 4466) ---------- So the pthread ID I want is 4466 in this case, and it is assighed to the variable $pthread.... (4 Replies)
Discussion started by: tmf33uk
4 Replies

6. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: stateperl
2 Replies

7. 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

8. 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

9. Shell Programming and Scripting

awking and grepping parts of files: the 'super diff'

OKAY---- Here's what I must do. I have two files. I need to compare the two files such as with the diff command. I am adding FILENEW to FILEOLD If fields $1, $2, $5, and 6 are the same, then I don't want to add FILENEW records to FILEOLD. If they are not, then append the lines. Is... (11 Replies)
Discussion started by: jeffpas
11 Replies

10. Shell Programming and Scripting

Awking!! Printing decimal output is struck

Hi friends, I have a small problem with AWK. I am not able to print decimal values! :confused: below is my code: #! /bin/awk -f awk BEGIN{printf("%d",123)}; -> This prints the integer properly. x=111 awk BEGIN{printf("%d",x)}; -> This doesnt print! :( Please help me solve this. It... (4 Replies)
Discussion started by: divzz
4 Replies
Login or Register to Ask a Question