Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-16-2005, 03:41 PM   #1
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 537

Rep: Reputation: 79
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:
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:
but i don't arrive to find the good sed syntax to do it.
Old 11-16-2005, 03:59 PM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Try this...
sed 's/\(.*K\).*/\1/' file.txt
Old 11-16-2005, 04:13 PM   #3
Senior Member
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 54
Or this: sed 's/[kK].*/K/' foo.txt
Old 11-16-2005, 05:41 PM   #4
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 537

Original Poster
Rep: Reputation: 79

that work just fine.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
No new line at end of file? What does this mean? BajaNick Programming 12 05-19-2014 09:39 PM
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 10:42 AM
how to delete duplicates entries in xml file using sed/awk/sort ? catzilla Linux - Software 1 10-28-2005 03:57 PM
trying to delete a line with sed deoren Linux - General 2 01-03-2005 10:26 PM
delete line specified by variable wihin shel script with sed lnchatterbox Linux - Newbie 2 02-23-2004 02:24 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:24 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration