The UNIX and Linux Forums  

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
append a ' to the $1 $2 ppass Shell Programming and Scripting 2 05-26-2008 10:59 AM
ftp append brdholman UNIX for Dummies Questions & Answers 1 10-31-2007 10:02 AM
how to append into array thru awk manas_ranjan Shell Programming and Scripting 2 09-21-2007 07:00 AM
append to fle using sed shweta_d Shell Programming and Scripting 2 06-13-2007 03:57 AM
Append and redirect Anna UNIX for Dummies Questions & Answers 1 07-06-2001 06:18 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-31-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Append using awk

Hi All,

I have a problem with my awk script. I am trying to append the whole line to another file called " file.txt " but i can't. I suppose there's something wrong in the way that i pipe. I canot use " nawk -f awk_script input > file.txt " because i have a 2nd input.
Can any expert give some advise?

Input:
wwwwww
0999 k= 1
0999 bb= 111
wwwwww
** QQQAAAR1 ccc ccc cc cc ccc 2007
wwwwww
wwwwww
0001 k= 1
0001 bb= 222
wwwwww
0002 k= 1
0002 *bb= 333
** abc ccc cc cc cc cc 2007
wwwwww
0001 k= 1
0001 bb= 444
wwwwww
0002 k= 1
0002 bb= 555
wwwwww
wwwwww
0003 k= 1
0003 bb= 666
wwwwww
** QQQAAAR1 ccc ccc cc cc ccc 2007
wwwwww
0003 k= 1
0003 bb= 777
wwwwww
0004 k= 1
0004 *bb= 888
0005 k= 1
0005 bb= 999



Code:
FNR==NR && $1 == "**" && $2 ~ /^QQQ/ && $2 ~ /R1$/ && $8 == "2007" {
CODE = $2 ;print $0|getline > file.txt ; next};

  #2 (permalink)  
Old 11-01-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926

Code:
nawk 'NR == FNR && /^** QQQ[^ ]*R1 .* 2007$/ {
	CODE = $2
	print > "file.txt"
	next
}' filename

  #3 (permalink)  
Old 11-03-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Quote:
Originally Posted by radoulov View Post
Code:
nawk 'NR == FNR && /^** QQQ[^ ]*R1 .* 2007$/ {
	CODE = $2
	print > "file.txt"
	next
}' filename
Thanks radoulov!!! It worked!!
But i don;t really understand this portion of the code " /^** QQQ[^ ]*R1 .* 2007$/ " .
Can you help me understand it better ?
  #4 (permalink)  
Old 11-04-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
Quote:
Originally Posted by Raynon View Post
[...]
But i don;t really understand this portion of the code " /^** QQQ[^ ]*R1 .* 2007$/ " .
It's a regular expression that matches the records that
begin with ** (^ anchors the beginning of the line)
followed by QQQ, then [^ ]* means zero or more occurrences
of characters other than a space: "^" as the first character
after the "[" indicates character(s) except those
in square brackets, followed by a literal R1, space and
zero or more occurrences of any character followed by
a space and 2007 at the end of the line.
  #5 (permalink)  
Old 11-04-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Thanks radoulov!!!
You are such a pro at this!!
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 02:43 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