Simple AWK command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple AWK command?
# 1  
Old 10-12-2007
Simple AWK command?

I am not that good with AWK. Is there a simple awk command I could use to get the word "this" from the following text besides using "awk -F ":" '{print $2} | awk -F " " '{print $1}"?

:this is:that is:
# 2  
Old 10-12-2007
Code:
echo ":this is:that is:" | awk '{sub(":","",$1);print $1}'

# 3  
Old 10-12-2007
Quote:
Originally Posted by ghostdog74
Code:
echo ":this is:that is:" | awk '{sub(":","",$1);print $1}'

ghostdog74, thanks for the quick reply that worked great. i am not sure how it worked. how would i get the word "this" from the following?

echo ":is this:is that:"
# 4  
Old 10-12-2007
Quote:
Originally Posted by 2dumb
ghostdog74, thanks for the quick reply that worked great. i am not sure how it worked. how would i get the word "this" from the following?

echo ":is this:is that:"
it depends on what the word "this" really means. Is it a word you want to find from a string? If that's the case, you can simply search for it.
Code:
echo  ":is this:is that:"  | awk '/this/{print "i got this"}'

If not, you should provide a sample of your input and describe more clearly what you are trying to do.
# 5  
Old 10-12-2007
Code:
echo ':this is:that is:' | nawk -F'[ :]' '{print $2}'

# 6  
Old 10-12-2007
What I have is the output of a time command. What I want is to grab the hours from the line "real" then times the hours by 60 to get the minutes. Then add that to the minutes. To get the total minutes the command ran.

So what I am looking for is a good way to extract the total number of hours and minutes. However some times the output will not show the hours.

Some times it looks like this:
real 1h10m55.46s
user 0m0.00s
sys 0m0.01s

Other times it may be:
real 59m20.32s
user 0m0.00s
sys 0m0.01s
# 7  
Old 10-12-2007
You can format the time output, so you don't need awk
(this is for bash, check your shell/time documentation/manual for details):

Code:
bash 3.2.25(1)$ time sleep 1

real    0m1.004s
user    0m0.000s
sys     0m0.004s
bash 3.2.25(1)$ TIMEFORMAT="%0lR"
bash 3.2.25(1)$ time sleep 1
0m1s

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

A simple awk command

Hi there, given the file FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7 FIELD8 FIELD9 FIELD10 FIELD11 Why does not awk '$6 == "FIELD6" {$6=="GREEN"}1' file do the work and replace"FIELD6" by "GREEN"? And second question, what is the purpose of the "1" at the end of... (5 Replies)
Discussion started by: la2015
5 Replies

3. Shell Programming and Scripting

Simple awk

Hi, this must be a simple but this is my first interaction with shell and awk. following is a log file needed to parse (2 lines separated by a line break for clarity): 2013-07-27 13:32:09,043 - ERROR - PerformanceUtility - Thread-14 - Performance - 9b348407-4f57-4983-a057-a55669821f68 |... (12 Replies)
Discussion started by: liv2luv
12 Replies

4. Shell Programming and Scripting

Simple awk help

Hey all, so I'm using AWK in a project at work, to generate xml from csv. So far things are going relatively smoothly, but I have one thing I can't figure out. For every field in each row, I must generate <entry name=KWNamex>Field</entry> Then I will need to pull data from a second file... (6 Replies)
Discussion started by: Parrakarry
6 Replies

5. Shell Programming and Scripting

Simple awk use

Hi, I have a file such that: 40454,31,48,4,1304.967741935484,1 31708,25,48,4,1268.32,1 20900,64501,671,788,0.3240259840932699,0 20137,51358,834,743,0.3920908135051988,0 I want to replace the 6th column by "ones" if it is 1, and with "zeros" if it is 0. Thanks. (6 Replies)
Discussion started by: shekhar2010us
6 Replies

6. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

7. Shell Programming and Scripting

awk command for simple join command but based on 2 columns

input1 a_a a/a 10 100 a1 a_a 20 200 b1 b_b 30 300 input2 a_a a/a xxx yyy a1 a1 lll ppp b1 b_b kkk ooo output a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies

8. Shell Programming and Scripting

simple awk help

Whats the syntax to find all lines that matches a text and print out specific fields after the match? ex: 1: some random text 2: Full name: John E. Smith 3: some random text 4: Full name: Mary J. Lue 5: some random text So I'd like to print out First names or last names or everything... (2 Replies)
Discussion started by: linuxdude
2 Replies

9. Shell Programming and Scripting

simple awk

when I execute this awk stmt .. awk "/log_directory/ { print $5}" /opt/dba/oraadmin/tools/tmp_purge_op.log it's returning the whole line as .. IRMD118_LISTENER1 parameter "log_directory" set to /opt/oracle/10.2/network/log/ my expected output is : /opt/oracle/10.2/network/log what... (7 Replies)
Discussion started by: talashil
7 Replies

10. UNIX for Dummies Questions & Answers

Need help with a simple command

You don't know the name of the command that could do a particular task. What command could you run to find the name of the command? (4 Replies)
Discussion started by: kurtbudd1
4 Replies
Login or Register to Ask a Question