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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tabs and spaces problem

Status
Not open for further replies.

dessie1981

Programmer
May 9, 2006
116
GB
Hi everyone,

Im quite new to awk and i am having a problem parsing a txt file.
The problem is that i have a number of different columns seperated by tabs yet some of the columns have spaces in them, awk is seeing the spaces as a seperator also

I am running awk from the command line

e.g.

myfile.txt

tab1 tab2 tab3 tab4 tab4 tab4

cat myfile.txt|awk '{print $4}'

will return only "tab4"

How do i get awk to return "tab4 tab4 tab4"

i have also tried

cat myfile.txt|awk '{FS = "/t"}{print $4}'

But it just returns blanks.

Any help would be greatful.

Regards
Des
 
And this ?
awk '{FS = "[!]\[/!]t"}{print $4}' myfile.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PH,

Yes i tried this and it has some funny output. Just prints the first word in the 4th column and the rest of the file is blank.

I have also created a test file that i know for sure is properly seperated by tabs and i am getting the same results.

Any more ideas would be greatful??

Des
 
no when i use "BEGIN" i just get a blank output, doh!

Des
 
Hi

If do not put the [tt]BEGIN[/tt], then the first line will be already read & parsed when you set the [tt]FS[/tt]. So for the first line have no chance to work.

What I proposed works for me with GNU [tt]awk[/tt] 3.1.1. What [tt]awk[/tt] you use ?

Feherke.
 
Hi

Strange. Just a last idea : did you applied PHV's suggestion too by changing the forward slash ( / ) to backslash ( \ ) ? Because both changes are required : the backslash and the [tt]BEGIN[/tt].

Feherke.
 
Your right , i missed that , thanks a million for your help!
Works fine now.
I should keep a closer eye to detail on the posts.

Regards
Des
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top