LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 03-15-2012, 12:44 AM   #1
Trd300
Member
 
Registered: Feb 2012
Posts: 89

Rep: Reputation: Disabled
Count occurrence of character in field and print in a new field


%%%%%

Last edited by Trd300; 05-01-2012 at 04:36 AM.
 
Old 03-15-2012, 03:10 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,193

Rep: Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784
Something like:
Code:
awk 'BEGIN{OFS="|"}{if(NR == 1)$6 = "Field6";else $6 = 0}NR > 1 && $4 ~ /x/{$6 = split($4,_,"x") - 1}1' file
 
Old 03-15-2012, 04:36 AM   #3
Trd300
Member
 
Registered: Feb 2012
Posts: 89

Original Poster
Rep: Reputation: Disabled
Thanks grail !

I see what you mean. It is a bit like using the character I am looking for as FS and count the number of field.

Like:
Code:
awk 'BEGIN {FS="x"} {print $0, NF-1}' file
Except that the split option restricts the move to the field only.
I didn't know that the split option returns the number of array by default.

Thanks again grail !
 
Old 03-20-2012, 03:51 AM   #4
Trd300
Member
 
Registered: Feb 2012
Posts: 89

Original Poster
Rep: Reputation: Disabled
awk: sort variable value and assign a name accordingly

error
 
Old 03-20-2012, 04:32 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,193

Rep: Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784
error???? Would you like to provide more information?
 
Old 03-21-2012, 07:57 PM   #6
Trd300
Member
 
Registered: Feb 2012
Posts: 89

Original Poster
Rep: Reputation: Disabled
No no, it works !

I didn't write on the good thread, my mistake !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk: how to print a field when field position is unknown? elfoozo Programming 12 08-18-2010 03:52 AM
awk printing from Nth field to last field sebelk Programming 2 01-08-2010 09:39 AM
php question, how do I get a return from a field within a field? cherrington Programming 11 04-29-2009 01:27 AM
What is the ninth (9th) character or field in the output string of rpm -V ? zimon Linux - Distributions 1 08-28-2006 02:47 PM
AWK: print field to end, and character count? ridertech Linux - Newbie 1 05-07-2004 05:07 PM


All times are GMT -5. The time now is 08:21 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration