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
Replacing a string in nth line maxmave Shell Programming and Scripting 1 06-04-2008 06:32 PM
To cut end string from line visu Shell Programming and Scripting 7 12-21-2007 02:22 AM
regexp to get first line of string jonas.gabriel Shell Programming and Scripting 3 05-09-2007 04:46 AM
How I Can get String From the Line habuzahra UNIX for Dummies Questions & Answers 2 10-29-2006 07:55 AM
Add string after line X alienET Shell Programming and Scripting 2 10-13-2005 10:52 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 02-01-2007
ozzman ozzman is offline
Registered User
  
 

Join Date: Feb 2007
Location: Aus Syd
Posts: 10
Unhappy get the NF of a string line

Hi all,

New here and new to shell as well.
Currently I have a problem when use echo $1 | awk -F\| '{print NF}' to get the NF of input string separated by "|". There's input contains more than 100 fields, then I have error awk: record `dd|14/06/2003|ssssss...' has too many fields . What do I solve this problem?

Thanks
  #2 (permalink)  
Old 02-01-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,411
Use gawk, or try...
Code:
echo $(($(echo $1|tr -dc '|'|wc -c)+1))

  #3 (permalink)  
Old 02-01-2007
ozzman ozzman is offline
Registered User
  
 

Join Date: Feb 2007
Location: Aus Syd
Posts: 10
Thumbs up problem solved

Thanks Ygor, that solves the problem.
  #4 (permalink)  
Old 02-01-2007
ozzman ozzman is offline
Registered User
  
 

Join Date: Feb 2007
Location: Aus Syd
Posts: 10
Question Get field value.

since the awk can't handle 100+ fields. what do I use to get one of the field value, say field 45. Currently I am using
Code:
echo $1|awk -F\| '{print $45}' .

And I don't know why I can't get gawk command in my environment.

Thanks
  #5 (permalink)  
Old 02-01-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,411
Try...
Code:
oldIFS=$IFS
IFS='|'
set $1
IFS=$oldIFS
echo $#
echo ${45}

  #6 (permalink)  
Old 02-02-2007
ozzman ozzman is offline
Registered User
  
 

Join Date: Feb 2007
Location: Aus Syd
Posts: 10
Thumbs up thanks Ygor. that's really helpful


Got it. Cheers
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 07:01 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