The UNIX and Linux Forums  

Go Back   A UNIX és Linux Forums > Top Fórumok > Shell programozás és Scripting
.
google unix.com



Shell programozás és Scripting Post kérdések KSH, CSH, SH, Bash, Perl, PHP, SED, AWK ÉS EGYÉB shell szkriptek és shell script nyelvek itt.

Több, UNIX és Linux fórum témák Ön által talált Hasznos
Szál Thread Starter Fórum Válaszok Utolsó hozzászólás
cat fájl1 read line-per-line akkor grep-A 15 vonalak meg fileb irongeekio Shell programozás és Scripting 6 01-28-2009 06:30 AM
Csatlakozzon a sorokat fordított. függelék sor 1., 2. sor. dwalley Shell programozás és Scripting 7 08-04-2008 08:11 AM
Appending sorszám minden egyes sorban, és kapok teljes sorok száma chiru_h Shell programozás és Scripting 2 03-25-2008 10:19 AM
2 sor, hogy az 1 vonal segítségével awk cdfd123 Shell programozás és Scripting 2 10-03-2007 08:44 PM
Appending line / vonalak sed nir_s Shell programozás és Scripting 28 07-24-2005 03:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Téma eszközök Keresés a téma Rate Thread Megjelenítési módok
  #1 (permalink)  
Old 04-22-2009
Pinnacle pinnacle is offline
Regisztrált felhasználó
  
 

Join Date: Apr 2009
Hozzászólások: 182
Awk 2 sor, 1 sor

Bemeneti fájl:

Idézet:
Bemenet:
host1 server1
database1 5
host2 server2
database2 5
host3 KISZOLGÁLÓ3
database3 5
Kívánt eredményt:
Idézet:
host1 server1 database1 5
host2 server2 database2 5
host3 KISZOLGÁLÓ3 database3 5
Megpróbáltam a következő kódot:

Kód:
nawk '{for(i=1; i<=NR; i+2) {print NR,$0; getline ;print \n $0; NR=NR+2}}' temp

De doesnt jogot ad eredményt.
Help is appreciated
  #2 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderátor
  
 

Join Date: Feb 2005
Helyszín: Boston, MA
Hozzászólások: 5.131

Kód:
paste -d' ' - - < temp
OR
nawk 'ORS=(FNR%2)?FS:RS' temp

  #3 (permalink)  
Old 04-22-2009
Pinnacle pinnacle is offline
Regisztrált felhasználó
  
 

Join Date: Apr 2009
Hozzászólások: 182
Idézet:
Originally Posted by vgersh99 View Post
Kód:
paste -d' ' - - < temp
OR
nawk 'ORS=(FNR%2)?FS:RS' temp
Köszönöm pro


Kód:
paste -d' ' - - < temp
nawk 'ORS=(FNR%2)?FS:RS' temp

Méltányolná, ha el tudja magyarázni ezt.
  #4 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderátor
  
 

Join Date: Feb 2005
Helyszín: Boston, MA
Hozzászólások: 5.131
Idézet:
Originally Posted by zenit View Post
Köszönöm pro


Kód:
paste -d' ' - - < temp
nawk 'ORS=(FNR%2)?FS:RS' temp

Méltányolná, ha el tudja magyarázni ezt.
Elolvashatja a man oldalakat a "Beillesztés", hogy egy magas szintű, mit csinál - a többi egyszerű.
awk:

Kód:
(FNR%2) - get a 'modulo' of the current file RecordNumber (FNR) over 2 - every OTHER line.
If the mod is NON-zero, return 'FS' (FieldSeparator)
If the mod is zero, return RecordSeparator (RS)
ORS= - assign the returned value to the OutputRecordSeparator (ORS)

In other words...
If we're dealing with the ODD record/line numbers (1,3,5,7 etc), print the line and FS (separate the next line)
If we're dealing with the EVEN record/line numbers (2.4.6.8 etc), print the line and the ORS (which is by default is newLine).

  #5 (permalink)  
Old 04-22-2009
Pinnacle pinnacle is offline
Regisztrált felhasználó
  
 

Join Date: Apr 2009
Hozzászólások: 182
Idézet:
Originally Posted by vgersh99 View Post
Elolvashatja a man oldalakat a "Beillesztés", hogy egy magas szintű, mit csinál - a többi egyszerű.
awk:

Kód:
(FNR%2) - get a 'modulo' of the current file RecordNumber (FNR) over 2 - every OTHER line.
If the mod is NON-zero, return 'FS' (FieldSeparator)
If the mod is zero, return RecordSeparator (RS)
ORS= - assign the returned value to the OutputRecordSeparator (ORS)
 
In other words...
If we're dealing with the ODD record/line numbers (1,3,5,7 etc), print the line and FS (separate the next line)
If we're dealing with the EVEN record/line numbers (2.4.6.8 etc), print the line and the ORS (which is by default is newLine).
Köszönöm Uram!

Kisebb változás; szüksége kimenet vesszővel elválasztva.

Én megpróbáltam, de ez szintaktikai hiba.


Kód:
nawk '{ORS=(FNR%2)?FS:RS}; OFS=,' temp

Appreciate your help
  #6 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderátor
  
 

Join Date: Feb 2005
Helyszín: Boston, MA
Hozzászólások: 5.131

Kód:
nawk -F, 'ORS=(FNR%2)?FS:RS' temp

  #7 (permalink)  
Old 04-22-2009
Pinnacle pinnacle is offline
Regisztrált felhasználó
  
 

Join Date: Apr 2009
Hozzászólások: 182
Awk a fura terek (output a Sybase szerver)

Idézet:
Originally Posted by vgersh99 View Post
Kód:
nawk -F, 'ORS=(FNR%2)?FS:RS' temp
Amikor beillesztett input file honlapján. Van valami furcsa terek, de amikor én azt hiszem, ragasztott honlapján eltávolítani azt. így én fűződő azt.


Requried eredménye
host1, server1, database1, 5
host2, server2, database2, 5
host3, KISZOLGÁLÓ3, database3, 5

Talált Én kapok is csatolni

Appreciate help
Attached Files
File Type: txt inputfile.txt (375 Byte, 21 letöltés)
File Type: txt output_i_am_getting.txt (363 Byte, 19 letöltés)
Closed Thread

Könyvjelzõk

Téma eszközök Keresés a téma
Keresés a téma:

Részletes keresés
Megjelenítési módok Rate this thread
Rate this thread:

Posting szabályzat
Ön nem post new threads
Ön nem post válaszok
Ön nem post Csatolmányok
Ön nem szerkeszteni az üzeneteidet

BB kód van Be
Smilies vannak Be
[IMG] kód Be
HTML kód Ki
Trackbacks vannak Be
Pingbacks vannak Be
Refbacks vannak Be




Minden idő GMT -4. Az idő most 09:08 PM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Nyelvre lefordítva Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
A UNIX és Linux Fórum Tartalom Copyright © 1993-2009. Minden jog Reserved.Ad menedzsment RedTyger

Content Relevant URLs by vBSEO 3.2.0