LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-25-2008, 09:19 AM   #1
(00)
LQ Newbie
 
Registered: Jan 2008
Posts: 5

Rep: Reputation: 0
Post bash script to remove first characters from every line


I downloaded bazaar.txt for a shell scripting-pdf, so that I can follow the examples I want to get rid of the margin (there are two spaces in front of every line. I've tried

sed '/^ /!d' bazaar.txt | tr -s ' ' > bazaar2.txt

but this will only remove one space, one more to go using the same method btw does not work twice. Hints, links, information and flames all appreciated.
 
Old 01-25-2008, 09:45 AM   #2
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
To cut off a range of characters you can do:
Code:
cut -b 1-2 --complement bazaar.txt
This cuts off the range of '1-2' or in this case the range from 1 to 2 characters inclusive (the first two characters). For example it would be 5-23 if you wanted to cut off characters 5 to 23 inclusive.
 
Old 01-25-2008, 03:49 PM   #3
(00)
LQ Newbie
 
Registered: Jan 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Lightbulb It Works!

-It's funny, I'm doing this so I have a file to work with to learn shell-scripting(shell-scripting.pdf)...and to get passed the 'sed' and 'tr' lessons, 'cut' would have been next! Anyway thanks texmex
 
Old 01-26-2008, 06:34 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
sed 's/^ *//' file > newfile

Removes any number of spaces at the beginning of the line
 
Old 01-29-2009, 10:45 PM   #5
garethsays
LQ Newbie
 
Registered: Jan 2009
Posts: 2

Rep: Reputation: 0
Example files

HI
I'm also trying to wade throught the shellscripting.pdf book but am unable to find the files it refers to in the examples. Both the bazaar.txt and emails{1,2,3}.txt.

COuld you tell me where you obtained them from?
 
Old 08-17-2009, 01:25 PM   #6
mak1453
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Download

Hi,

Can you please let me know where to download the files listed in shell-scripting.pdf? http://www.catb.org/~esr/writings/cathedral-bazaar/ does not work. I also not able to download other files, emails1.txt, emails2.txt emails3.txt columns.txt telnum.txt. I would really appreciate if someone can tell me where to get these files.

Thanks,
Mak
 
Old 07-27-2011, 11:24 AM   #7
trynreadme
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Rep: Reputation: 0
Remove specific beginning character

I'm trying to combine two text files and remove common phrases in each file. I've done that with
'comm -3 text1.txt text2.txt > new.txt'
But it puts them in columns so I have a column for text1 and a column for text2 so I did
'comm -3 --output-delimiter=0 text1.txt text2.txt > new.txt'
but now I have 0's in front of text2 phrases. I was wondering if there was anything I could && or | to, to remove the 0's or maybe even a better way of doing this. I would greatly appreciate any nudges in the right direction.
 
Old 07-29-2011, 01:06 PM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Try using 'uniq -u' instead.
 
Old 08-01-2011, 10:28 AM   #9
trynreadme
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Rep: Reputation: 0
Thank you

I ended up using
Code:
cat ~/txtfolder/* |sort|uniq|less > new.txt
so essentially the same just added a couple, thanks though.
 
  


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 On
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
non-ascii characters in bash script and unicode igor.R Linux - Newbie 31 12-29-2012 03:45 AM
Remove file location from bash line okos Linux - Newbie 5 10-30-2007 02:46 AM
unwanted characters returned with bash find - how to remove? babag Programming 5 06-10-2007 09:36 PM
inserting special characters into mysql with bash script ihopeto Linux - Newbie 1 12-05-2006 12:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:25 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