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!

Take out values with spaces and tabs 1

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
Hi,
I've a problem. I need to take out values on a file.
I do something as:

awk '{ print ""$1"\t"$2"\t"$4""
}' /input > /output


But my file is as:
aa a tab bb tab cc tab dd
ff tab qq q tab gg dr tab koi
a a tab a tab c tab dd fd
gg tab c tab x c tab jf

where I put tab is a tab key: the problem is that sometimes values of some column have a space. For on example of above my output should be as:

aa a bb dd
ff qq q koi
a a a dd fd
gg c jf

How can I do it?

Thanks


 
Hi

I am not sure that I understand correctly the requirement. Do you want to change the currently mixed field separators to space ( ) ?
Code:
awk -vOFS=' ' '{$1=$1}1' /input/file

[gray]# or[/gray]

awk '{gsub(/[ \t]+/," ")}1' /input/file

Feherke.
 
Thanks for your answer, but it isn't my problem.
I need to take out values where a same column can have values with spaces.
For example: I represent column1 with a's, column2 with b's, column3 with c's and column4 with d's.
a bb b cc c dd
aaa a b c d
aa a bb b b c dd d
a a b b c d d

And I need to extract column1, column2 and column4. Therefore, my output should be:
a bb b dd
aaa a b d
aa a bb b b dd d
a a b b d d

Between a column and other is separated with tab key.

Txs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top