Reputation: 519
I have a file containing a bunch of lines like this blabla-any-characters**,**numbers-and-characters
I would like to keep everything before the first comma and remove everything else.
Any hint how to do this with awk or sed?
Thanks
Upvotes: 2
Views: 13085
Reputation: 37039
You can do that with awk
relatively easily.
$ cat test.txt
blabla-any-characters**,**numbers-and-characters
john,smith
hello,world
$ awk -F',' '{print $1}' test.txt
blabla-any-characters**
john
hello
Upvotes: 2
Reputation: 50034
For awk
you could use:
awk -F"," '{print $1}' file
Which will delimit each record using a comma and then only print the first element.
Upvotes: 2
Reputation: 784998
You can use sed like this:
sed -i.bak 's/,.*$//' file
,.*$
will match anything after first comma and will replace it by an empty string.
-i.bak
is for inline editing in sed.
Upvotes: 8