help with awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with awk command
# 1  
Old 08-19-2012
help with awk command

Hi,
i'm new here and i need your help with awk.
i got a file with this pattern of lines for example:

15/08/2012 13:04:03:265|FrameworkManager |INF|inbound 15/08/2012 13:04:03:265 80 120 srv_500 38112345999 ContentDiscovery searchByKeywordPage 0 <param[0] == Cell 0 = [subscriber Id = [ field Name = [ USERNAME ]; value = [ test ]; ]; device Id = [ value = [ Mozilla/5.0 (Linux; U; Android 2.3.6; sr-rs; U8655-1 Build/HuaweiU8655) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 ]; identifier Type = [ 3 ]; ]; locale = [ en ]; max Results = [ 1000 ]; start Index = [ 0 ]; entity Types = [ Cell 0 = [10] ; ]; media Types = [ local Item = [ ]; ]; portal = [ Telenor Serbia Mobile Portal ]; screen = [ Mobile ]; sorting Parameters = [ Cell 0 = [entity Type = [ 11 ]; sorting Entity Parameters = [ Cell 0 = [order By = [ Number of downloads ]; direction = [ desc ]; ] ; ]; ] ; ]; reserved Attr = [ local Item = [ ]; ]; ALLOWED_ ENTITY_ TYPES_ TO_ = [ Cell 0 = [4] ;Cell 1 = [10] ;Cell 2 = [4] ;Cell 3 = [3] ;Cell 4 = [9] ; ]; promoted Entity Types = [ local Item = [ ]; ]; ] ;Cell 1 = [zdrava ishrana] ;Cell 2 = [value = [ Apps Home ]; entity Type = [ 2 ]; ] ; /> current Node = [ category = [ ID:cat_513 NAME: en - Apps Home CONTENT_PROVIDER:null ]; packages Ids = [ Cell 0 = [value = [ Telenor Serbia Wap Package ]; entity Type = [ 0 ]; ] ; ]; has Special Offer = [ false ]; absolute URLPrefix = [ http://market.dobrestvari.rs:80/DS ]; ]; menu = [ ]; menu Size = [ 0 ]; favorite = [ false ]; sorting Override By Portal Enabled = [ true ];

i marked the words i need to get out from this block as bold... please help me.. :]
# 2  
Old 08-19-2012
If you want to remove those bold words, you can also use sed command.
# 3  
Old 08-19-2012
maybe i wasn't clear enough... sorry about that
i would like to get a text file (or to echo, i don't mind) with the bold values i marked...
# 4  
Old 08-19-2012
Rule ? Which field to show using bold ? Input file size ? If big, then maybe awk is the best tool.
Basic idea something like:
Code:
#!/usr/bin/someposixshell      
# (ksh, bash, dash, ...)
# get terminal bold on/off sequences using tput from terminfo database
bold_on=$(tput smso)
bold_off=$(tput rmso)

# using in the command line
echo a $bold_on b $bold_off c

# or in  the awk

awk -v bold_on="$bold_on" -v bold_off="$bold_off"  '
{ $5=bold_on $5 bold_off  # change some field including bold and bold off
  print $4 ,$5,$6
  # or only print something using bold_on bold_off
  print $2 ,bold_on,$3,bold_off,$6
  printf "some %s somevalue %s something else \n",bold_on,bold_off
} ' input_file

# 5  
Old 08-19-2012
no... this is not what i meant....


look, i have log files, they contain text blocks like the one i attached.
what i would like to do is to take from each block only the words i marked in bold.... i don't need them to be bold on my output or something... just showed you which word i need ....

for example, in the block i attached i would want to see in the output :

15/08/2012 13:04:03:265 38112345999 zdrava ishrana

i hope now it is clear...

thanks Smilie
# 6  
Old 08-19-2012
If the lines are all the same length and can be sorted into columns then you could use cut to print only the three columns.
# 7  
Old 08-19-2012
Quote:
Originally Posted by ctrllior
look, i have log files, they contain text blocks like the one i attached.
You've given us nothing but that one block of text. If we had a few of them to examine, we might at least be able to make an educated guess about which parts of the text are constant and which change.

Even better, why don't you do that work for us. Analyze your data and then give us the details that we need. Otherwise, how are we supposed to know how to find relevant words? Is your data semicolon delimited? If so, do the words occur in the same field every time? Or if semicolons are an unreliablebe indicator, are there keywords in the text that we can use? For example, if there's a word that never changes and one of the sought after words is always 3 words after that unchanging key, we could use that.

Long story short, you need to put some effort into this as well; take the time to figure out your data and explain it to us. Otherwise, this thread will grow long and frustrating for all involved.

Regards,
Alister

Last edited by alister; 08-19-2012 at 11:55 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass awk field to a command line executed within awk

Hi, I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date). All my attempts failed this far. Here's an example. It works fine with timestamp hard-codded into the command echo "1381653229 something" |awk 'BEGIN{cmd="date -d... (4 Replies)
Discussion started by: tuxer
4 Replies

2. Shell Programming and Scripting

Multiple command execution inside awk command during xml parsing

below is the output xml string from some other command and i will be parsing it using awk cat /tmp/alerts.xml <Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

4. 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

5. 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

6. UNIX for Dummies Questions & Answers

Basic awk question...getting awk to act on $1 of the command itself

I have a script problem that I am not able to solve due my very limited understanding of unix/awk. This is the contents of test.sh awk '{print $1}' From the prompt if I enter: ./test.sh Hello World I would expect to see "Hello" but all I get is a blank line. Only then if I enter "Hello... (2 Replies)
Discussion started by: JasonHamm
2 Replies

7. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

8. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies
Login or Register to Ask a Question