Sponsored Content
Full Discussion: awk: don't print sub-arrays
Top Forums UNIX for Dummies Questions & Answers awk: don't print sub-arrays Post 302678905 by beca123456 on Monday 30th of July 2012 03:37:04 AM
Old 07-30-2012
awk: don't print sub-arrays

Hi !

I have this input:
Code:
12{11}{11110}{80}3456
{123}15{60}9876{8083}34

I try to work on individual numbers between braces.
3 possible cases (here I used colours to be clearer only):
- there is no "0" among the characters between braces: so we don't touch anything.
- there is a "0" among characters between braces, and the number of characters between braces is >2 ("0" included): e.g. {1110} needs to be written as ({111})%
- there is a "0" among characters between braces, and the number of characters between braces = 2 ("0" included): e.g. {10} needs to be written as 1%

From the input above, I should obtain this output:
Code:
12{11}({1111})%8%3456
{123}156%9876({883})%34

My first attempt was with this code, but I get the same as input:
Code:
BEGIN{FS=OFS=""}

{
	a = split($0,b,"{")
	
	for(i=1; i<=a; i++){
	    c = split(b[i],d,"}")
	    
	    for(j=1; j<=c; j++){
	    	e = split(d[j],f,"")
	    	
	    	if(d[j] ~ /0/ && e == 2){
	    		gsub(/0/,"",d[j])
	    		gsub(/$/,"%",d[j])
	    	}
	    	
	    	else if(d[j] ~ /0/ && e > 2){
	    		gsub(/^/,"({",d[j])
	    		gsub(/$/,"})%",d[j])
	    		gsub(/0/,"",d[j])
	    	}
	    	
	    	else if(d[j] !~ /0/){
	    		gsub(/^/,"{",d[j])
	    		gsub(/$/,"}",d[j])
	    	}
	    }
	}
}1

I expect to make some modifications after but i would like to understand why it doesn't print anything first.

Thanks for your help !

Last edited by beca123456; 07-30-2012 at 08:49 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

may be simple but i don't know -- Print current date from C program

How to print current date of the Unix system accessing thru C++ program ? I wrote like this #include <time.h> ....... time_t tt; struct tm *tod; .... time(&tt); tod = localtime(&tt); cout << tod->tm_mon + 1 << "/" << tod->tm_mday << "/" ... (6 Replies)
Discussion started by: ls1429
6 Replies

2. Shell Programming and Scripting

arrays in awk???

Been struggling with a problem, I have been trying to do this in awk, but am unable to figure this out, I think arrays have to be used, but unsure how to accomplish this. I have a input file that looks like this: 141;ny;y;g 789;ct;e;e 23;ny;n;u 45;nj;e;u 216;ny;y;u 7;ny;e;e 1456;ny;e;g... (3 Replies)
Discussion started by: craigsky
3 Replies

3. Shell Programming and Scripting

awk arrays

Guys, OK so i have been trying figure this all all day, i guess its a pretty easy way to do it. Right, so i have to column of data which i have gotten from one huge piece of data. What i would like to do is to put both of these into one array using awk. Is this possible?? If so could... (1 Reply)
Discussion started by: imonthejazz
1 Replies

4. Shell Programming and Scripting

awk arrays can do this better - but how?

Hi, I have spent the afternoon trawling Google, Unix.com and Unix in a Nutshell for information on how awk arrays work, and I'm not really getting too far. I ahve a batch of code that I am pretty sure can be better managed using awk, but I'm not sure how to use awk arrays to do what I'm... (1 Reply)
Discussion started by: littleIdiot
1 Replies

5. HP-UX

awk don't work in hp-ux 11.11

Hello all! I have problem in hp-ux 11.11 in awk I want to grep sar -d 2 1 only 3 column, but have error in awk in hp-ux 11.11 Example: #echo 123 234 | awk '{print $2}' 123 234 The situattions in commands bdf | awk {print $5}' some... In hp-ux 11.31 - OK! How resolve problem (15 Replies)
Discussion started by: ostapv
15 Replies

6. UNIX for Dummies Questions & Answers

Help to know the various possible uses of awk arrays

Hi to all, I write this time to ask for different syntax or ways of arrays within awk and uses. Since I don't know how actually could work and the real potencial of awk arrays, I look for a proactive reply/help in order to get more information than it seems I'm trying to get. I think I... (2 Replies)
Discussion started by: cgkmal
2 Replies

7. Programming

std::cout and gfortran print*, don't output to the screen

I am not sure where to post this other than here. I am trying to figure out why an app gives different output when compiled under Ubuntu 10.10 and CentOS 5.5. I am pretty sure that the issue is that the Cent version has gcc 4.1 installed, while Ubuntu has gcc 4.4. I am trying to print from some... (20 Replies)
Discussion started by: LMHmedchem
20 Replies

8. Shell Programming and Scripting

help in awk arrays!

Hi, buddies I am new to shell scripting and trying to solve a problem. I read about arrays in awk that they are quite powerful and are associative in nature. Awk Gurus Please help! I have a file: Id1 pp1 0t4 pp8 xy2 Id43 009y black Id6 red xy2 Id12 new pp1 black I have... (5 Replies)
Discussion started by: geli21
5 Replies

9. Shell Programming and Scripting

Compare strings between 2 arrays and print number in AWK

Hi to everyone, Please some help over here. Hi have array a with 6 elements and array b with 3 elements as shown inside BEGIN{} statement. I need help to get the correct sintax (the part in red) to compare if string from array b is in array a and print the number related for each match.... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

10. Shell Programming and Scripting

Using arrays with awk

I'm a little stuck and would be grateful of some advice! I have three files, two of which contain reference data that I want to add to a line of output in the third file. I can't seem to get awk to print array contents as I would expect. The input files are: # Input file AAA,OAA,0313... (2 Replies)
Discussion started by: maccas17
2 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 05:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy