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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Always numbers? Try this:
sed 's/\(^[0-9]*\).*$/\1/' inputfile
or
tr -d '[:alpha:][:blank:]' < inputfile
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
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
sed '2d' inputfile
awk 'NR!=2 {print}' inputfile
File "input" looks like:
Open in new window
Run this one
Open in new window