Link to home
Create AccountLog in
Avatar of shay911
shay911

asked on

How do i use sed or grep or a linux command to omit the second line

How do i use sed or grep or a linux command to omit the second line

for example i have a file

243299384892  firstname lastname
324324324323 firstname lastname


I want to run a command so i get the the numbers and omit the firstname lastname?

Thank you
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Always the same? cut can be easier.

File "input" looks like:
243299384892  firstname lastname
324324324323 firstname lastname

Open in new window


Run this one
cut -f 1 -d ' ' input
243299384892
324324324323

Open in new window

Always numbers? Try this:

sed 's/\(^[0-9]*\).*$/\1/' inputfile

or

tr -d '[:alpha:][:blank:]' < inputfile
A loop using only shell builtins:

while read line; do echo ${line%% *}; done < inputfile
And to take your question literally (i.e. delete the second line of a file):

sed '2d'  inputfile

awk 'NR!=2 {print}' inputfile