The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
please explain the below mail2sant Shell Programming and Scripting 1 04-04-2008 08:04 AM
Please can any one explain this ${0##/} gadege Shell Programming and Scripting 2 04-01-2008 03:26 PM
please explain this dummy_needhelp Shell Programming and Scripting 2 10-15-2007 01:17 AM
Can anyone explain plz r_W213 UNIX for Advanced & Expert Users 3 03-27-2007 04:52 AM
if [ $? -eq 0 ] .. can someone explain this? ranjita.c Shell Programming and Scripting 5 10-03-2006 07:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-26-2006
hitmansilentass hitmansilentass is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 37
Explain awk

Hi,

I found this command in this forum, but, couldnt understand much from it.

could any one help me understand that???

the commands are :
Code:
awk '{sub(/ ~/,""); printf $0 ($0~/\|$/?ORS:"")}' file1 > file2
awk '{sub(/~ */,x);printf $0(/\|$/?ORS:x)}'
awk '{sub(/~ */,x);sub(/\|$/, "|\n")}8' ORS="" file1 >file2
the purpose is to remove all "~" characters and fix the broken lines

Code:
existing file data:

24|john|account ~ info |56|
25|kuo|account ~ journal |58|
27|kim|account ~ journal |59|
28|San|account ~ 
journal |60|
29|jay|account ~ journal |26|
29|Nan|account ~ 
journal |66|
30|Kee|account ~ journal |27|

Output: 

24|john|account info |56|
25|kuo|account journal |58|
27|kim|account journal |59|
28|San|account journal |60|
29|jay|account journal |26|
29|Nan|account journal |66|
30|Kee|account journal |27|
I am not able to understand the last part of the command where ORS(output record separator) is used
  #2 (permalink)  
Old 09-26-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
Code:
awk '{sub(/ ~/,""); printf $0 ($0~/\|$/?ORS:"")}' file1 > file2
For each input line :

sub(/ ~/,"");
Remove'~' and all following spaces (replaced by empty sting "").

($0~/\|$/?ORS:"")
If the input line ends with '|' then the value of the expression ORS, else the value is an empty string.
ORS is a variable that contains the Output Record Separator that is used par awk when printing data to stdout (with print statement); The default value of ORS is '\n'.

printf $0 ($0~/\|$/?ORS:"")
Displays the input line, followed by a new line (ORS) if ending with '|'.


The 3 commands are varitions a the same technique.


jean-Pierre.
  #3 (permalink)  
Old 09-27-2006
hitmansilentass hitmansilentass is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 37
Thanks jean-Pierre, are you from grenoble by an chance???
  #4 (permalink)  
Old 09-27-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
Wink

Quote:
Thanks jean-Pierre, are you from grenoble by an chance???
Pas de chance, plus à l'ouest : Bordeaux.


Jean-Pierre.
  #5 (permalink)  
Old 09-27-2006
hitmansilentass hitmansilentass is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 37
Quote:
Originally Posted by aigles
Pas de chance, plus à l'ouest : Bordeaux.


Jean-Pierre.
I asked you because one of the developers of my application was called by your name and is from grenoble. anyways, looks like you have a vast knowledge of unix scripting. do you mind, telling me where do you refer????
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0