LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash script to remove first characters from every line (https://www.linuxquestions.org/questions/linux-general-1/bash-script-to-remove-first-characters-from-every-line-616269/)

(00) 01-25-2008 09:19 AM

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.

H_TeXMeX_H 01-25-2008 09:45 AM

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.

(00) 01-25-2008 03:49 PM

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

pixellany 01-26-2008 06:34 AM

sed 's/^ *//' file > newfile

Removes any number of spaces at the beginning of the line

garethsays 01-29-2009 10:45 PM

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?

mak1453 08-17-2009 01:25 PM

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

trynreadme 07-27-2011 11:24 AM

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.

H_TeXMeX_H 07-29-2011 01:06 PM

Try using 'uniq -u' instead.

trynreadme 08-01-2011 10:28 AM

Thank you
 
I ended up using
Code:

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


All times are GMT -5. The time now is 07:02 PM.