03-25-2008
syntax
The following awk syntax works, but i need this script to be modified to also sum field4 values by distinct field1, field2, field3
awk '{print substr($0,1,27),substr($2,index($2,"_")+1)," ",substr($0,49)}' testfile.dat > testfile2.dat
Current file
W2_2009 275 999_2 8
W2_2009 275 99_2 7
W25_2009 275 97_1 5
W25_2009 275 96_1 4
New file
W2_2009 275 2 15
W25_2009 275 1 9
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Dear Experts
I am trying to find if it is possible to combine unix commands in awk program. For example if it is possible embed rm or ls or any unix command inside the awk program and while it is reading the file besides printing be able to do some unix commands. I am thinking may be just print... (2 Replies)
Discussion started by: Reza Nazarian
2 Replies
2. Shell Programming and Scripting
The following awk script creates a file b.dat.
awk '{print substr($0,1,27),substr($2,index($2,"_")+1)," ",substr($0,49)}' a.dat > b.dat
I need this script to be modified to also sum $3 values by distinct $1 and $2
fields.
Current file
W2_2009275 2 8
W2_2009275 2 7
W1_2009275 1... (3 Replies)
Discussion started by: mnnarendra
3 Replies
3. Shell Programming and Scripting
I want to substitute a charactor "PAN" with "TAN" in a shell, I used sed command in shell, it wo'nt work but the same is run from command prompt it was successful. the command is
sed ' s/PAN/TAN/g ' <i/p> > <o/p>
sed ' s/^M/^M/g ' <i/p> > <o/p> (1st ^M is Ctrl+V+M, 2nd should be line feed/next... (1 Reply)
Discussion started by: anil_kut
1 Replies
4. Shell Programming and Scripting
Hi
I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it
The code is that:
{
if (NF==17){
print $0
}else{
fields=NF;
all=$0;
while... (2 Replies)
Discussion started by: fate
2 Replies
5. UNIX for Dummies Questions & Answers
Hi All,
I am new to unix.
In this forum some days back, I have read something like below:
1) Do not use perl if awk can do your work.
2) Do not use awk if sed can do your work.
.
.
.
I do not re-collect the whole thing. I think it is good to know the precedence of using these... (2 Replies)
Discussion started by: Prathmesh
2 Replies
6. Shell Programming and Scripting
I've input as ,
abcd|
ef
123456|
78|
90
Desired output as,
abcdef
1234567890
Anyone please give the solution. (5 Replies)
Discussion started by: jinixvimal
5 Replies
7. Shell Programming and Scripting
Hi folks,
I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex.
I have a bunch of update statements with all columns in a file which I need to convert into insert statements.
UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies
8. How to Post in the The UNIX and Linux Forums
I have a fixed length file that looks like
a@ a00 a00000 a00 a000000 a00 a0000 a0000 a00000000 a01
a@ a1 a2 a11 a22 a12 a13 a44 a45 a54 a65 a76 a77
a@ a1 a3 a6 a7 a9 a8 a2 a7 a8 a8 a9 a0
b@ b00 b00000 b00... (1 Reply)
Discussion started by: RJG
1 Replies
9. Shell Programming and Scripting
I have a fixed length file a.txt that looks like
a@ a00 a00000 a00 a000000 a00 a0000 a0000 a00000000 a01
a@ a1 a2 a11 a22 a12 a13 a44 a45 a54 a65 a76 a77
a@ a1 a3 a6 a7 a9 a8 a2 a7 a8 a8 a9 a0
b@ b00... (7 Replies)
Discussion started by: RJG
7 Replies
10. UNIX for Beginners Questions & Answers
Greetings all,
I am looking for a version of Linux that I can practice my scripting skills on. Currently, I support a massive system running on AIX. I want to do more with awk, sed, grep, and even perl. I am looking for something I can throw on a VM on my personal laptop and mess around with.... (5 Replies)
Discussion started by: jeffs42885
5 Replies