Link to home
Start Free TrialLog in
Avatar of mechanicus01
mechanicus01Flag for Mexico

asked on

Remove First Word From Each Line in File

Hello
I need a shell script to remove the first word from each line in a text file.
The file looks like this:

KERB5_TAG-43 KERB5 SET REALM ""
KERB5_TAG KERB5 SET SRVTAB ""

Open in new window


I am looking to remove the KERB5_TAG-43 and KERB5_TAG.
Avatar of farzanj
farzanj
Flag of Canada image

sed "s/^[A-Za-z0-9_]*//" filename

Use -i if you want to make changes to the file
Avatar of mechanicus01

ASKER

Some of the lines have a "-" followed by a number.
Ex:
LDAP-TAG-92
LDAP-TAG-93

Open in new window



SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sed "s/^[A-Za-z0-9_-]*//" filename
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, thanks...Let me figure out how to distribute the points.
@farzani: cut will work just fine, as the OP says: "The file looks like this" - no way telling that the your sed pattern A-Za-z0-9_- will work in all cases.

Both cut and sed work perfectly for the sample given. awk would be more flexible in recognizing whitespace, tabs etc. We could ask for more details about the source file instead of making assumpitons ;)
Thanks.. they all worked but the cleanest using cut. Sed with regex worked but not all lines..