cut or nawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut or nawk
# 1  
Old 07-23-2012
cut or nawk

Hello
I have the next problem. I have a output with this format:
Code:
 msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

   211   28706 2012/07/21 01:38 SERVER12        32768 user/XXXX/INBOX /SERVER01-02/=user/01/f0/=XXXXX XXXXX   lrswipcda
     0       0 2008/09/17 09:09 SERVER12            - user/XXXXX/Enviats /SERVER01-02/=user/01/f0/=XXXXX/=+Enviats XXXXX       lrswipcda

I need to do a cut:
/SERVER01-02/=user/01/f0/=XXXXX
But the number of characters is different betwen lines
I trie use nawk (awk doesn't work in this version of solaris) unsuccessful.
Could you helpme?
Thanks
Moderator's Comments:
Mod Comment code tags please


---------- Post updated at 06:10 AM ---------- Previous update was at 05:25 AM ----------

Mmm I'm trying and:
nawk '/busti/{print $8}' ruta.txt
With this result
Code:
/SERVER01-02/=user/36/85/=USER1
/SERVER01-02/=user/36/85/=USER1/=+Enviats
/SERVER01-02/=user/36/85/=USER1/=+Esborranys
/SERVER01-02/=user/36/85/=USER1/=+Paperera
/SERVER01-02/=user/81/97/=USER2
/SERVER01-02/=user/81/97/=USER2/=+Eliminats
/SERVER01-02/=user/81/97/=USER2/=+Enviats
/SERVER01-02/=user/81/97/=USER2/=+Esborranys

I only need extracts
Code:
/SERVER01-02/=user/36/85/=USER1
/SERVER01-02/=user/81/97/=USER2

Could you helpme?
Thanks

Last edited by jim mcnamara; 07-23-2012 at 07:30 AM..
# 2  
Old 07-23-2012
Code:
nawk '/busti/ && match($8,/(\/[^\/]*){5}/) {print substr($8,RSTART,RLENGTH)}' ruta.txt

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 07-23-2012
Thanks but doesn't work
Code:
root@SERVER01:/opt/scripts\ > nawk '/busti/ && match($8,/(\/[^\/]*){5}/) {print substr($8,RSTART,RLENGTH)}' ruta2.txt
root@SERVER01:/opt/scripts\ >
root@SERVER01:/opt/scripts\>vi ruta2.txt
/SERVER01-01/=user/a3/85/=USER1
/SERVER01-01/=user/a3/85/=USER1/=+Eliminats
/SERVER01-01/=user/a3/85/=USER1/=+Enviats
/SERVER01-01/=user/a3/85/=USER1/=+Esborranys
/SERVER01-02/=user/c6/30/=USER2
/SERVER01-02/=user/c6/30/=USER2/=+Eliminats
/SERVER01-02/=user/c6/30/=USER2/=+Enviats
/SERVER01-02/=user/c6/30/=USER2/=+Esborranys
/SERVER01-02/=user/84/60/=USER3
/SERVER01-02/=user/84/60/=USER3/=+Eliminats
/SERVER01-02/=user/84/60/=USER3/=+Enviats
/SERVER01-02/=user/84/60/=USER3/=+Esborranys

# 4  
Old 07-23-2012
Run the command on the original file (I think it's ruta.txt)..not on the records you've extracted. And, awk, by no means, will change your original file, you'll need to redirect the output somewhere.
# 5  
Old 07-23-2012
Thanks Elixir
Yes, I run the command on the original ruta.txt, with the same result. Any result :-(
The origina ruta.txt contains:
Code:
  0       0 2012/07/23 10:47 SERVER12        32768 user/USER1/INBOX /SERVER01-02/=user/c6/30/=USER1 USER1        lr
swipcda
     0       0 2012/07/18 14:18 SERVER12            - user/USER1/Eliminats /SERVER01-02/=user/c6/30/=USER1/=+Eliminats 790
991670  lrswipcda
   183    6659 2012/07/18 14:18 SERVER12            - user/USER1/Enviats /SERVER01-02/=user/c6/30/=USER1/=+Enviats 7909916
70      lrswipcda
     0       0 2012/07/17 11:34 SERVER12            - user/USER1/Esborranys /SERVER01-02/=user/c6/30/=USER1/=+Esborranys 7
90991670        lrswipcda
  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

     0       0 2011/03/08 11:50 SERVER12        32768 user/USER2/INBOX /SERVER01-02/=user/84/60/=USER2 USER2   lrswipcda 
     0       0 2008/09/16 11:36 SERVER12            - user/USER2/Eliminats /SERVER01-02/=user/84/60/=USER2/=+Eliminats dblan
coo     lrswipcda
     0       0 2008/09/16 11:36 SERVER12            - user/USER2/Enviats /SERVER01-02/=user/84/60/=USER2/=+Enviats USER2       lrswipcda
     0       0 2008/09/16 11:36 SERVER12            - user/USER2/Esborranys /SERVER01-02/=user/84/60/=USER2/=+Esborranys dbl
ancoo   lrswipcda
  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

     0       0 2009/10/20 12:29 SERVER11        32768 user/USER3/INBOX /SERVER01-01/=user/76/16/=USER3 USER3   lrswipcda 
     0       0 2008/09/16 12:20 SERVER11            - user/USER3/Eliminats /SERVER01-01/=user/76/16/=USER3/=+Eliminats elaca
rta     lrswipcda
     0       0 2008/09/16 12:20 SERVER11            - user/USER3/Enviats /SERVER01-01/=user/76/16/=USER3/=+Enviats USER3       lrswipcda
     0       0 2008/09/16 12:20 SERVER11            - user/USER3/Esborranys /SERVER01-01/=user/76/16/=USER3/=+Esborranys ela

After to do
Code:
nawk '/busti/{print $8}' ruta.txt  > ruta2.txt

The result is:

Code:
/SERVER01-01/=user/a3/85/=USER1
/SERVER01-01/=user/a3/85/=USER1/=+Eliminats
/SERVER01-01/=user/a3/85/=USER1/=+Enviats
/SERVER01-01/=user/a3/85/=USER1/=+Esborranys
/SERVER01-02/=user/c6/30/=USER2
/SERVER01-02/=user/c6/30/=USER2/=+Eliminats
/SERVER01-02/=user/c6/30/=USER2/=+Enviats
/SERVER01-02/=user/c6/30/=USER2/=+Esborranys
/SERVER01-02/=user/84/60/=USER3
/SERVER01-02/=user/84/60/=USER3/=+Eliminats
/SERVER01-02/=user/84/60/=USER3/=+Enviats
/SERVER01-02/=user/84/60/=USER3/=+Esborranys

If exceute your command, the result is:
Code:
root@SERVER01:/opt/scripts\ > nawk '/busti/ && match($8,/(\/[^\/]*){5}/) {print substr($8,RSTART,RLENGTH)}' ruta.txt
root@SERVER01:/opt/scripts\ >

Thanks for your reply. I continued researching

Last edited by capilla; 07-23-2012 at 11:28 AM..
# 6  
Old 07-23-2012
I can't see "busti" in "ruta.txt"...how did you get "ruta2.txt"?Smilie
# 7  
Old 07-23-2012
Yes yes, sorry. I change the name of the servers & partitions for security. Inside ruta.txt:
Code:
 msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

     0       0 2011/03/08 11:50 bustia12        32768 user/USER1/INBOX /bustia01-02/=user/84/60/=USER1 USER1   lrswipcda 
     0       0 2008/09/16 11:36 bustia12            - user/USER1/Eliminats /bustia01-02/=user/84/60/=USER1/=+Eliminats      lrswipcda
     0       0 2008/09/16 11:36 bustia12            - user/USER1/Enviats /bustia01-02/=user/84/60/=USER1/=+Enviats USER1       lrswipcda
     0       0 2008/09/16 11:36 bustia12            - user/USER1/Esborranys /bustia01-02/=user/84/60/=USER1/=+Esborranys d   lrswipcda
  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

  msgs  Kbytes last msg         partition   quotaroot mailbox path and acl

Sorry I do replacement for security
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

3. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

4. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

5. Shell Programming and Scripting

Nesting - two nawk into one nawk

hi people; this is my two awk code: nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies

6. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies
Login or Register to Ask a Question