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
  Search this Thread
Old 09-02-2008, 01:20 PM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
awk help


I am cutting some address fields from a text file and i want to read this address fields in my awk program. example of address file fields..

xxyy899891 James street London.

add1=`cut -c12-30'

when i tried to read this into my awk scrip it is giving error as 'long file name`. I found the error that when there is a space in the cut fieled i.e., betweeen James and street, street and London it is not reading by awk script. So how to read this type of fields into awk script.
 
Old 09-02-2008, 01:36 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
In awk the default field separator is, like bash, [[:space:]]+

You can change this by the FS= directive in the BEGIN: section. Look in info awk for help.

The cut can then be accomplished with a call to, e.g., substr, which is also described in the awk (or gawk) info file.
 
Old 09-02-2008, 02:21 PM   #3
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 54
If they are space separated you could just choose wanted columns with, say: "| awk {'print $2,$3,$4'}"
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
awk question on handling *.CSV "text fields" in awk jschiwal Programming 8 05-27-2010 07:23 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
Some comments on awk and awk scripts makyo Programming 4 03-02-2008 06:39 PM
awk help uttam_h Programming 9 10-16-2007 11:32 AM
using awk wedgeworth Linux - Newbie 9 02-20-2004 08:48 AM


All times are GMT -5. The time now is 09:58 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration