Removing from beginning to first : using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing from beginning to first : using awk
# 1  
Old 10-31-2010
Removing from beginning to first : using awk

A have a file

Code:
npt02-sr40-syn-dc0p014-32x24drw.log:0. Best Value   = 0.00144914
npt02-sr40-syn-dc0p014-32x24drw.log:1. Best Value   = 0.00115706
npt02-sr40-syn-dc0p014-32x24drw.log:2. Best Value   = 0.00094345
npt02-sr40-syn-dc0p014-32x24drw.log:3. Best Value   = 0.000925552
npt02-sr40-syn-dc0p014-32x24drw.log:4. Best Value   = 0.000894649
npt02-sr40-syn-dc0p014-32x24drw.log:5. Best Value   = 0.000762455
npt02-sr40-syn-dc0p014-32x24drw.log:6. Best Value   = 0.000762455
npt02-sr40-syn-dc0p014-32x24drw.log:7. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw.log:8. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw-run2.log:0. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw-run2.log:1. Best Value   = 0.000699646
npt02-sr40-syn-dc0p014-32x24drw-run2.log:2. Best Value   = 0.000699646

I want to remove from each line everything until : and then renumbering the first number from 0, so the resulting file looks as below.

Code:
0. Best Value   = 0.00144914
1. Best Value   = 0.00115706
2. Best Value   = 0.00094345
3. Best Value   = 0.000925552
4. Best Value   = 0.000894649
5. Best Value   = 0.000762455
6. Best Value   = 0.000762455
7. Best Value   = 0.00073609
8. Best Value   = 0.00073609
9.. Best Value   = 0.00073609
10. Best Value   = 0.000699646
11. Best Value   = 0.000699646

# 2  
Old 10-31-2010
It works in above example if you only have run2 or else needs modification...

Code:
 
awk -F: '/run2/{print "1"$2;next}{print $2}' infile

---------- Post updated at 09:39 AM ---------- Previous update was at 09:30 AM ----------

Or if you have more run's...

Code:
 
 awk -F: '/run[0-9]/{print (substr($1,36,1)-1)$2;next}{print $2}' infile

# 3  
Old 10-31-2010
Code:
awk '{sub(/[^:]*:[0-9]*\.[ \t]*/,x);print NR-1 ". " $0}' infile

# 4  
Old 10-31-2010
I also want that only the first index value of 0 is outputted

This the line at run2 with index value 0 is deleted and thus the Best Value for it should not be shown.

npt02-sr40-syn-dc0p014-32x24drw-run2.log:0. Best Value = 0.00073609

Hence

Code:
npt02-sr40-syn-dc0p014-32x24drw.log:0. Best Value   = 0.00144914
npt02-sr40-syn-dc0p014-32x24drw.log:1. Best Value   = 0.00115706
npt02-sr40-syn-dc0p014-32x24drw.log:2. Best Value   = 0.00094345
npt02-sr40-syn-dc0p014-32x24drw.log:3. Best Value   = 0.000925552
npt02-sr40-syn-dc0p014-32x24drw.log:4. Best Value   = 0.000894649
npt02-sr40-syn-dc0p014-32x24drw.log:5. Best Value   = 0.000762455
npt02-sr40-syn-dc0p014-32x24drw.log:6. Best Value   = 0.000762455
npt02-sr40-syn-dc0p014-32x24drw.log:7. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw.log:8. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw-run2.log:0. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw-run2.log:1. Best Value   = 0.000699646
npt02-sr40-syn-dc0p014-32x24drw-run2.log:2. Best Value   = 0.000699646

should result in

Code:
0. Best Value   = 0.00144914
1. Best Value   = 0.00115706
2. Best Value   = 0.00094345
3. Best Value   = 0.000925552
4. Best Value   = 0.000894649
5. Best Value   = 0.000762455
6. Best Value   = 0.000762455
7. Best Value   = 0.00073609
8. Best Value   = 0.00073609
9. Best Value   = 0.000699646
10. Best Value   = 0.000699646

# 5  
Old 10-31-2010
Quote:
Originally Posted by kristinu
I also want that only the first index value of 0 is outputted

This the line at run2 with index value 0 is deleted and thus the Best Value for it should not be shown.

npt02-sr40-syn-dc0p014-32x24drw-run2.log:0. Best Value = 0.00073609

Hence

Code:
npt02-sr40-syn-dc0p014-32x24drw.log:0. Best Value   = 0.00144914
npt02-sr40-syn-dc0p014-32x24drw.log:1. Best Value   = 0.00115706
npt02-sr40-syn-dc0p014-32x24drw.log:2. Best Value   = 0.00094345
npt02-sr40-syn-dc0p014-32x24drw.log:3. Best Value   = 0.000925552
npt02-sr40-syn-dc0p014-32x24drw.log:4. Best Value   = 0.000894649
npt02-sr40-syn-dc0p014-32x24drw.log:5. Best Value   = 0.000762455
npt02-sr40-syn-dc0p014-32x24drw.log:6. Best Value   = 0.000762455
npt02-sr40-syn-dc0p014-32x24drw.log:7. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw.log:8. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw-run2.log:0. Best Value   = 0.00073609
npt02-sr40-syn-dc0p014-32x24drw-run2.log:1. Best Value   = 0.000699646
npt02-sr40-syn-dc0p014-32x24drw-run2.log:2. Best Value   = 0.000699646

should result in

Code:
0. Best Value   = 0.00144914
1. Best Value   = 0.00115706
2. Best Value   = 0.00094345
3. Best Value   = 0.000925552
4. Best Value   = 0.000894649
5. Best Value   = 0.000762455
6. Best Value   = 0.000762455
7. Best Value   = 0.00073609
8. Best Value   = 0.00073609
9. Best Value   = 0.000699646
10. Best Value   = 0.000699646

Then Scrutinizer solution might be what you want...
# 6  
Old 10-31-2010
Code:
cut -d\. -f3- < infile |awk '{print NR-1".",$0}'

# 7  
Old 10-31-2010
However it does not remove the line containing index value 0 that occur from run 2 onwards. I don't want the Best Value for those in the file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting text on multiple lines, then removing a beginning and end patterns

I have a file similar to the below. I am selecting only the paragraphs with @inlineifset. I am using the following command sed '/@inlineifset/,/^ *$/!d; s/@inlineifset{mrg, @btpar{@//' $flnm >> $ofln This produces @section Correlations between seismograms,,,,}} ... (5 Replies)
Discussion started by: Danette
5 Replies

2. Shell Programming and Scripting

awk - help in removing some text

Hey Guys, Earlier I asked a question under Solaris, which I got great help... thanks. Although I got the script working for what it really needed to do, I am looking for a bit of help to change the output for nicer reading. my script gets a list of zones under a global-zone and puts this... (4 Replies)
Discussion started by: dakelly
4 Replies

3. UNIX for Beginners Questions & Answers

Removing characters from beginning of multiple files

Hi, I have been searching how to do this but I can't seem to find how to do it. Hopefully someone can help. I have multiplr files, 100's example 12345-zxys.213423.zyz.txt. I want to be able to take all these files and remove the first '12345-' from each of the files. '12345-' these characters... (5 Replies)
Discussion started by: israr75
5 Replies

4. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

5. Shell Programming and Scripting

Removing hyphen from beginning and end of a word only.

It is very simple to remove a hyphen from a word anywhere in that word using a simple sed command (sed -i 's/-//g' filename), but I am not able to figure out how to do this: For example, apple -orange tree pipe- banana-shake dupe- What my output should look like: apple orange tree... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

Beginning awk question

I have a report that I'd like to print columns headers on. The code appears as follows: gawk '{for (i=1; i<=NF; i++) if ($i < 0) $i = -$i; print }'|gawk '{ printf "%-78s%-30s%-30s%-30s\n", $1,$2, $3, $4 }' |awk '{for (i=1; i<=NF; i++) if ($i < 0) $i = -$i; print }' report_1020I am trying to make... (3 Replies)
Discussion started by: newbie2010
3 Replies

7. Shell Programming and Scripting

One of the awk column spilling on the new line from beginning

I am having a problem where the Compute field/column is spilling over to the new line. Here's the piece of code and the o/p:- Code Sniplet:- for id in `qstat -u "*" -q "$Queue" -s r |sed -n '3,$ p'|awk -F" " '{print $1}'` do NODELIST=`cat /scratch/$id.hostlist.*|awk -F" " '{print $1,$2}'|tr '... (5 Replies)
Discussion started by: grish
5 Replies

8. Shell Programming and Scripting

Removing one or more blank characters from beginning of a line

Hi, I was trying to remove the blank from beginning of a line. when I try: sed 's/^ +//' filename it does not work but when I try sed 's/^ *//' filename it works But I think the first command should have also replaced any line with one or more blanks. Kindly help me in understanding... (5 Replies)
Discussion started by: babom
5 Replies

9. Shell Programming and Scripting

Swapping lines beginning with certain words using sed/awk

I have a large file which reads like this: fixed-address 192.168.6.6 { hardware ethernet 00:22:64:5b:db:b1; host X; } fixed-address 192.168.6.7 { hardware ethernet 00:22:64:5b:db:b3; host Y; } fixed-address 192.168.6.8 { hardware ethernet 00:22:64:5b:db:b4; host A; }... (4 Replies)
Discussion started by: ksk
4 Replies

10. Shell Programming and Scripting

Using NR with two variables at the beginning of awk

hi My requirement is this: I have a file having around 100000 records pipe delimited. Now I want to compare record 1 with record 2 and similarly record3 with record 4, this goes on.. For this purpose i put a script as follows: #!bin/ksh ct_line=1 nxt_line=`expr ${ct_line} + 1` awk -F "|"... (1 Reply)
Discussion started by: ramkrix
1 Replies
Login or Register to Ask a Question