LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   delete the end of each line in a file with sed (https://www.linuxquestions.org/questions/linux-newbie-8/delete-the-end-of-each-line-in-a-file-with-sed-383756/)

angel115 11-16-2005 02:41 PM

delete the end of each line in a file with sed
 
Here is the problem
I have 1 file: foo.txt witch look like this:
Code:

123K    bla bla bla
12k      sdfnlkbbslfbqs
68456K dsfsfdsdfsqfze

and i want to delete every thing after the first "K" on each line. So after modification the file will look like this:
Code:

123K
12K
68456K

but i don't arrive to find the good sed syntax to do it.
:cry:

homey 11-16-2005 02:59 PM

Try this...
sed 's/\(.*K\).*/\1/' file.txt

makuyl 11-16-2005 03:13 PM

Or this: sed 's/[kK].*/K/' foo.txt

angel115 11-16-2005 04:41 PM

Thanks

that work just fine.


All times are GMT -5. The time now is 06:43 PM.