tags:

views:

425

answers:

5

File1:

hello   (OPTION1)   123456   123456   123456
world   (OPTION1)   123456   123456   123456
foo     (OPTION1)   123456   123456   123456
bar     (OPTION1)   123456   123456   123456

How would one remove each string after each first word in the textfile File1?

This would probably be down with awk/sed/cat - but I cannot figure it out. I'm still new to editing via these utilities - perhaps others will benefit from my question.

The first words are not predictive (no wild cards), each first word is unique.

+4  A: 

awk one liner:

awk '{ print $1 }' < inputfile > outputfile

sed one liner:

sed 's/^\([A-Za-z0-9]*\).*/\1/' < inputfile > outpufile
Chris J
Both commands achieved the outcome, as did those below. Awk seems to be a very interesting utility. Thanks to Igor and pavium for their time, it is well appreciated!
It's not necessary to redirect the input file in either case. Both programs accept filenames as arguments.
Dennis Williamson
+2  A: 

You can just trim everything from the first white space onwards:

sed '\s.*$//' <File1
igor
+3  A: 

try

awk '{print $1}' filename > filename2
pavium
+1  A: 

why to use the those tools even after after having the cut command

cut -f1 -d"\t" filename
Vijay Sarathi
because cut just cuts and nothing else. awk cuts and greps and seds and counts plus a whole lot more.
ghostdog74
BUt this serves his pupose ..as i think so..
Vijay Sarathi
A: 

Or just for fun, you could do it with perl

perl -ne '@a=split; print "$a[0]\n"' < file

Benj