LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2008, 07:17 PM   #1
tallmtt
Member
 
Registered: Jun 2005
Location: Georgia, USA
Distribution: Arch, Gentoo, Ubuntu
Posts: 91

Rep: Reputation: 15
SOLVED - bash script to remove everything in a line before a space


I have some files that need mass editing. The problem is that some lines are numbered and others are not - I want none of them to be numbered.

Example:
File-1:
blah
blah
blah
blah
23 blah
24 blah
25 blah
blah
blah
13 blah
2 blah

What I want:
File-2:
blah
blah
blah
blah
blah
blah
blah
blah
blah
blah
blah
blah



I am not good with sed or awk but have a hunch this is where they shine. I would like to run is:

cat File-1 | {code to remove everything before a space in each line} >> File-2

Any idea how to write the {code} part?

Last edited by tallmtt; 12-28-2008 at 07:41 PM.
 
Old 12-28-2008, 07:29 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
I am not good with sed or awk
Do you want to be? Really good tutorials here: http://www.grymoire.com/Unix

Remove everything up to and including the first space:

Code:
sed 's/[^ ]* //' oldfile > newfile
 
Old 12-28-2008, 07:40 PM   #3
tallmtt
Member
 
Registered: Jun 2005
Location: Georgia, USA
Distribution: Arch, Gentoo, Ubuntu
Posts: 91

Original Poster
Rep: Reputation: 15
You rock! Very quick response - worked flawlessly!

Excellent link also after my quick review - I do want to become better at both sed and awk - they seem to be able to do so much for everyone who knows them.

Thank you for both the response and the link.
 
  


Reply



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
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
bash script to remove first characters from every line (00) Linux - General 8 08-01-2011 10:28 AM
script to remove line ust Linux - Server 2 07-02-2008 05:46 AM
Remove file location from bash line okos Linux - Newbie 5 10-30-2007 02:46 AM
help with bash script: remove * to the last . in string drkstr Linux - Software 3 04-25-2006 04:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:48 AM.

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