Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field Separator

Status
Not open for further replies.

Navvy

Technical User
Apr 12, 2002
64
US
Hi...

I've been trying to separate fields in AWK using the line:

FS = ";"

...where ; is the field separator. However, this doesn't seem to work. Anyone got any ideas/suggestions?

Thanks in advance.
 
Need more info ... If the separator on your input file is a ; then a script like

awk '{BEGIN FS=";"}
{main awk code here}'

should work OK.

Greg.
 

Hi Navvy!

You can also use command-line argument -Fc to set field separator FS to the charater c; for example:

Code:
awk -F; '{ # awk code; print }' inputfile

Bye!

KP.
 
If you are printing to print out multilple values in one line separated by a ";" try this:

BEGIN { OFS = ";"; FS = ";" }

print $1,$2,$3


 
Hi all...

For some reason, none of these suggestions seem to work. The input file looks as follows:

ASBA ;USD/HKD ; 7.43423 ;01/09/02 ; 3.4555l; -656565656

Any other suggestions?
 

If I good see, your input file has two lines. Is this correct?

Which data you must extract from file?

KP.
 
Hey KP...

It's all on one line. But there are many records of the same format, all in one input file.

I don't know whether the white spaces are a problem?

Many thanks in advance for your help.
 
The below seems to work fine printing out the THIRD field from the file "navvy.txt" containig just one line mentioned above.

Tell us more HOW you run your script

vlad

nawk -f navvy.awk navvy.txt

----------------- navvy.awk ----------------------
BEGIN {
FS = ";"
}

{ print $3 }

----------------- navvy.awk ----------------------
 
With gawk 3.1.0/Linux 2.4.16

awk ' BEGIN {
FS = ";"
}
{
for (i=1 ; i < NF ; i++) {
print i, $i, NF ,NR, FS
}
}' file

Comes up with all correct info: What do you want the output
to look like?
 
It will be very easy to figure out the problem if you post your script along with the data.
 
Hi all...

Firstly, thanks for your efforts!

I'm running the script by:

cat text.txt | prog.awk >output
 

This is amaizing ;))

Pls post text.txt AND prog.awk

I simply hate debuggin' hypotheticals.... ;)

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top