Colon in awk script output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Colon in awk script output
# 1  
Old 02-13-2012
Colon in awk script output

I'm using AIX 5.3 and running a awk replace to modify data as follows:

Code:
 echo 1234: 1234 123 123 444 555 666 7777  | awk '/^:/{split($2,N);n=N[1]} {n=$1} {sub(n,n+10000000)}1'

10001234 1234 123 123 444 555 666 7777

dumb question.. how do I get the colon back in, so it outputs
Code:
10001234: 1234 123 123 444 555 666 7777

# 2  
Old 02-13-2012
I think a lot of those code blocks are redundant... But to get the colon back, put the colon back:
Code:
awk '/^:/{split($2,N);n=N[1]; sub(n,n+10000000); $1=$1":"}1'

# 3  
Old 02-13-2012
Quote:
Originally Posted by Corona688
I think a lot of those code blocks are redundant... But to get the colon back, put the colon back:
Code:
awk '/^:/{split($2,N);n=N[1]; sub(n,n+10000000); $1=$1":"}1'

that doesn't work. The output is:

Code:
1234: 1234 123 123 444 555 666 7777

---------- Post updated at 11:27 AM ---------- Previous update was at 10:37 AM ----------

figured it out myself finally...

Code:
echo 0034: 1234 | awk '/^:/{split($2,N);n=N[1]} {n=$1} {sub(n,n+10000000":")}1'

I didn't think the colon would work there.
# 4  
Old 02-13-2012
Code:
$  echo 1234: 1234 123 123 444 555 666 7777  | awk '{$1=$1+10000000":"}1'
10001234: 1234 123 123 444 555 666 7777

Regards,
Alister
# 5  
Old 02-13-2012
great... thanks.. much easier. I have a follow on question. my real data is like this:

Code:
7004: 38706 38707 38708 38709 38710 38711 38712 38713
7005: 38904 38905 38906

I can add 1000000 to the first number real easy now, but how can I add 1000000 to every number in a variable length string?

The output needs to be (taking the second row for ease)
Code:
1007005: 1038904 1038905 1038906

but there may be anything from 1 to 12 numbers per line.

---------- Post updated at 08:06 PM ---------- Previous update was at 07:26 PM ----------

again a workaround....but I did this:

Code:
awk '{n=$2} n{sub(n,n+1000000)}1' | awk '{n=$3} n{sub(n,n+1000000)}1'

repeated 10 times. Can you do a for loop inside awk?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

awk unique count of partial match with semi-colon

Trying to get the unique count of the below input, but if the text in beginning of $5 is a partial match to another line in the file then it is not unique. awk awk '!seen++ {n++} END {print n}' input 7 input chr1 159174749 159174770 chr1:159174749-159174770 ACKR1 chr1 ... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk does not find ids with semi-colon in the name

I am using awk to search $5 of the "input" file using the "list" file as the search criteria. So if the id in line 1 of "list" is found in "search" then it is counted in the ids found. However, if the line in "list" is not found in "search", then it is outputted as is missing. The awk below runs... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. UNIX for Dummies Questions & Answers

awk colon separated items

Hi, I need to filter my data based on items in column 23. Column 1 until column 23 are tab separated. This is how column 23 looks like: PRIMARY=<0/1:504:499,5:.:.:.:0.01:1:15:.> I want to extract lines if items 7 (separated by : ) in column 23 are more than 0.25 . In example above , item... (2 Replies)
Discussion started by: janshamsani
2 Replies

5. Shell Programming and Scripting

awk :help to parse a file to change to separated by colon ":"

Hi experts , I am trying to get the below output: file : 0/6/4/1 0x0019503C2E26 5 UP lan5 snap5 1 ETHER Yes 224 0/6/4/0 0x0019503C2E25 6 UP lan6 snap6 2 ETHER Yes 224 0/2/1/0 0x0019503E6900 0 UP lan0 snap0 3 ETHER Yes 224... (8 Replies)
Discussion started by: rveri
8 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. AIX

AIX HMC - Getting Colon ":" in output

Hi, I am executing below commands on HMC. I see that there is only colon ":" in output. Can someone please help why I am getting ":" in output? Why I am not getting proper output? xxxxx@yyyyhmc1:~> viosvrcmd -m PCC-p590#2-SN024D8F0 -p ppvio1 -c "lsmap -all" :xxxxx@yyyyhmc1:~> viosvrcmd... (0 Replies)
Discussion started by: marya
0 Replies

8. Shell Programming and Scripting

Script required to put colon

Hi Expert, I need help on script to put colon between two characters. From this line 60060160B18414009C557D9DE02CDF11 to this 60:06:01:60:B1:84:14:00:9C:55:7D:9D:E0:2C:DF:11 Any way to make it on script. (2 Replies)
Discussion started by: ranjancom2000
2 Replies

9. UNIX for Dummies Questions & Answers

Multiple field separators in awk? (First a space, then a colon)

How do I deal with extracting a portion of a record when multiple field separators are involved. Let's say I have: Mike Harrington;(555) 555-5555:250:100:175 Christian Dobbins;(555) 555-2358:155:90:201 Susan Dalsass;(555) 555-6279:250:60:50 Archie McNichol;(555) 555-1348:250:100:175 Jody... (3 Replies)
Discussion started by: doubleminus
3 Replies

10. Shell Programming and Scripting

script the output with awk

Please i need your help. i made this script with awk, this scripts count and list a pattern for each directory in the output as shown. but not as desired. i want the output will be listed in a tabular way, using awk: cuenta_cdrs() { for dir in * do cd $dir for file in * do ... (4 Replies)
Discussion started by: alexcol
4 Replies
Login or Register to Ask a Question