sed remove newlines and spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed remove newlines and spaces
# 1  
Old 04-08-2011
sed remove newlines and spaces

Hi all,

i am getting count from oracle 11g by spooling it to a file.
Now there are some newline characters and blank spaces i need to remove these.
pl provide me a awk/sed solution.
the spooled file is attached.
i tried this.. but not getting req o/p
Quote:
sed -n -e '2p' -e 's@[^0-9]@@g' 1.txt
# 2  
Old 04-08-2011
i got it..

Quote:
sed -e 's@[^0-9]@@g' -n -e /[0-9]/p 1.txt
thanks.
if anyone is having a simple one in awk then it will be better.
# 3  
Old 04-08-2011
Code:
awk '/./{gsub(" ","");print}' 1.txt

# 4  
Old 04-08-2011
Code:
sed 's/[   ]*//g;/^$/d' 1.txt

# 5  
Old 04-08-2011
Below would do the job, guess you would not need to again match the numbers and print them (/[0-9]/p) ..
Code:
 
sed  's@[^0-9]@@g' 1.txt

# 6  
Old 04-08-2011
I am curious to see if you can find something more simple than this :

Code:
xargs <1.txt

Smilie

... or better : use the relevant formatting option before you generate your spool so that no additionnal blank stuff comes out.
Code:
set TRIM ON
spool <yourfile>
...
spool off

You can also have a look at the WOR[D_WRAP] option here

Last edited by ctsgnb; 04-08-2011 at 05:22 AM..
These 2 Users Gave Thanks to ctsgnb For This Post:
# 7  
Old 05-17-2011
Code:
echo "         1" | awk '{print $1}'

awk automatically strips the leading spaces when determining arguments.

Last edited by Franklin52; 05-17-2011 at 03:40 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can't remove spaces with sed when calling it from sh -c

The following command works echo "some text with spaces" | sh -c 'sed -e 's/t//g''But this doesn't and should echo "some text with spaces" | sh -c 'sed -e 's/ //g''Any ideas? (3 Replies)
Discussion started by: Tribe
3 Replies

2. UNIX for Dummies Questions & Answers

Using sed to remove spaces from middle of the line

Hi, I need to correct href portion of the lines to edit out spaces from the line starting with position "<a href=" and ending at "target=" Below are 2 examples of extra space added by the server: <td width=251 colspan=9 rowspan=22> <font size=2 face="courier"><tt><style>{font:7pt Courier ... (4 Replies)
Discussion started by: friedmi
4 Replies

3. UNIX for Dummies Questions & Answers

Remove newlines

Hi buddy's my file are like this: s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30," ebdug gil",,4 but i want s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30,"ebdug gil",,4 any command or Shell script for this. please help me it's urgent to implement (33 Replies)
Discussion started by: Suneelbabu.etl
33 Replies

4. Shell Programming and Scripting

'for LINE in $(cat file)' breaking at spaces, not just newlines

Hello. I'm making a (hopefully) simple shell script xml parser that outputs a file I can grep for information. I am writing it because I have yet to find a command line utility that can do this. If you know of one, please just stop now and tell me about it. Even better would be one I can input... (10 Replies)
Discussion started by: natedawg1013
10 Replies

5. Shell Programming and Scripting

tr and sed remove spaces. how to stop this?

if the answer is obvious, sorry, I'm new here. anyway, I'm using tr to encrypt with rot-13: echo `cat $script | tr 'a-zA-Z' 'n-za-mN-ZA-M'` > $script it works, but it removes any consecutive spaces so that there is just one space between words. I've had this problem before while using sed to... (5 Replies)
Discussion started by: Trichopterus
5 Replies

6. Shell Programming and Scripting

How to remove spaces using awk,sed,perl?

Input: 3456 565 656 878 235 8 4 8787 3 7 35 878 Expected output: 3456 565 656 878 235 8 4 8787 3 7 35 878 How can i do this with awk,sed and perl? (10 Replies)
Discussion started by: cola
10 Replies

7. Shell Programming and Scripting

Remove improperly placed newlines

Hello, there. I have a file that's a horrible, horrible mess. (Basically, it's an export from a firewall config.) The people who generated the file didn't think that putting a newline in the middle of a hostname would ever be a problem. It is. Here's an example of the stuff in the file: ... (2 Replies)
Discussion started by: mikesimone
2 Replies

8. Shell Programming and Scripting

sed - remove spaces before 1rst occurence of string

seems easy but havent found in other posts... i want to delete any spaces if found before first occurence of ${AI_RUN} sed 's/ *\\$\\{AI_RUN\\}/\\$\\{AI_RUN\\}/' $HOME/temp1.dat i think i'm close but can't put my finger on it. :rolleyes: (6 Replies)
Discussion started by: danmauer
6 Replies

9. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

10. Shell Programming and Scripting

how to remove spaces in a string using sed.

Hello, I have the following to remove spaces from beginning and end of a string. infile=`echo "$infilename" | sed 's/^ *//;s/ *$//` How do I modify the above code to remove spaces from beginning, end and in the middle of the string also. ex: ... (4 Replies)
Discussion started by: radhika
4 Replies
Login or Register to Ask a Question